Each feature in detail MDN The page CSS property is used to specify the named page, a specific type of page defined by the @page at-rule .
Live preview Example from MDN
CSS HTML JS
Edit Reset Copy
@page toc {
size : a4 portrait ;
@top-center {
content : "Table of contents" ;
}
}
@page foreword {
size : a4 portrait ;
@top-center {
content : "Foreword" ;
}
}
@page introduction {
size : a4 portrait ;
@top-center {
content : "Introduction" ;
}
}
@page conclusion {
size : a4 portrait ;
@top-center {
content : "Conclusion" ;
}
}
@page chapter {
size : a4 landscape ;
@top-center {
content : "Chapter" ;
}
}
fieldset {
display : flex ;
flex-direction : row ;
justify-content : space-between ;
gap : 1 rem ;
width : fit-content ;
}
body {
font : 1.1 em sans-serif ;
}
@media print {
fieldset {
display : none ;
}
section {
font-size : 2 rem ;
font-family : "Roboto" , sans-serif ;
}
.chapter {
border : tomato 2 px solid ;
}
[ data-print = "grouped" ] > #toc ,
[ data-print = "paged" ] > #toc {
page : toc;
font-family : "Courier New" ;
}
[ data-print = "grouped" ] > #foreword ,
[ data-print = "paged" ] > #foreword {
page : foreword;
font-family : "Courier New" ;
}
[ data-print = "grouped" ] > #introduction ,
[ data-print = "paged" ] > #introduction {
page : introduction;
font-family : "Courier New" ;
}
[ data-print = "grouped" ] > #conclusion ,
[ data-print = "paged" ] > #conclusion {
page : conclusion;
font-family : "Courier New" ;
}
[ data-print = "grouped" ] > .chapter ,
[ data-print = "paged" ] > .chapter {
page : chapter;
}
[ data-print = "paged" ] > .chapter {
border : none ;
break-after : page ;
}
.chapter > ul {
columns : 2 ;
}
} <!-- print options in a fieldset -->
< fieldset id = "printStyle" >
< legend >How would you like to print</ legend >
< label for = "single" >
< input type = "radio" id = "single" name = "type" value = "single" checked />
No Pages
</ label >
< label for = "grouped" >
< input type = "radio" id = "grouped" name = "type" value = "grouped" />Pages with
Grouped Chapters
</ label >
< label for = "paged" >
< input type = "radio" id = "paged" name = "type" value = "paged" />
Chapters Paged
</ label >
< button id = "print" >Print</ button >
</ fieldset >
<!-- Content to be printed -->
< article id = "print-area" data-print = "single" >
< section id = "toc" >
< h2 >Table of contents</ h2 >
< ul >
< li >Foreword</ li >
< li >Introduction</ li >
< li >Chapter One - named pages</ li >
< li >Chapter Two - page orientation</ li >
< li >Chapter Three - page margins</ li >
< li >Conclusion</ li >
</ ul >
</ section >
< section id = "foreword" >
< h2 >Foreword</ h2 >
< p >
This book is all about how the CSS < code >@page</ code > at-rule can help
with printing HTML books.
</ p >
</ section >
< section id = "introduction" >
< h2 >Introduction</ h2 >
< p >
This book is a concept to show how an < em >HTML</ em > document can easily be
printed out in pages.
</ p >
</ section >
< section id = "chapter1" class = "chapter" >
< h2 >Named pages</ h2 >
< p >Lorem ipsum</ p >
</ section >
< section id = "chapter2" class = "chapter" >
< h2 >Page Orientation</ h2 >
< p >Lorem ipsum</ p >
</ section >
< section id = "chapter3" class = "chapter" >
< h2 >Page Margins</ h2 >
< p >There are 16 page margins that can be set:</ p >
< ul >
< li >@top-left-corner</ li >
< li >@top-left</ li >
< li >@top-center</ li >
< li >@top-right</ li >
< li >@top-right-corner</ li >
< li >@left-top</ li >
< li >@left-middle</ li >
< li >@left-bottom</ li >
< li >@right-top</ li >
< li >@right-middle</ li >
< li >@right-bottom</ li >
< li >@bottom-left-corner</ li >
< li >@bottom-left</ li >
< li >@bottom-center</ li >
< li >@bottom-right</ li >
< li >@bottom-right-corner</ li >
</ ul >
< p >They can be used to show what appears in these parts of the margin</ p >
</ section >
< section id = "conclusion" >
< h2 >Conclusion</ h2 >
< p >Now go ahead and write books.</ p >
</ section >
</ article > const printArea = document. querySelector ( "#print-area" );
const printButton = document. querySelector ( "#print" );
const printOption = document. querySelector ( "#printStyle" );
printOption. addEventListener ( "change" , ( event ) => {
if (event.target.value === "single" ) {
printArea.dataset.print = "single" ;
} else if (event.target.value === "grouped" ) {
printArea.dataset.print = "grouped" ;
} else {
printArea.dataset.print = "paged" ;
}
});
printButton. addEventListener ( "click" , () => {
window. print ();
}); Syntax auto | <custom-ident> Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Definition Initial auto Applies to boxes that create class A break points Inherited no (but see prose) Percentages n/a Computed value specified value Canonical order per grammar Animation type discrete Browser support First browser version supporting page Chrome 85 Edge 85 Firefox 110 Safari 1 Chrome Android 85 Safari iOS 1
First version with support, from MDN browser-compat-data.
Specification ↗ MDN reference ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@bottom-center { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@bottom-left { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@bottom-left-corner { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@bottom-right { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@bottom-right-corner { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@left-bottom { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@left-middle { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@left-top { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
Spec Authors can specify various aspects of a page box, such as its dimensions, orientation, and margins, within an @page rule. @page rules are allowed wherever rule-sets are allowed. An @page rule consists of the keyword @page, an optional comma-separated list of page selectors and a block of declarations (said to be in the page context). An @page rule can also contain other at-rules, interleaved between declarations. The current level of this specification only allows margin at-rules inside @page.
MDN The @page at-rule is a CSS at-rule used to modify different aspects of printed pages. It targets and modifies the page's dimensions, orientation, and margins. The @page at-rule can be used to target all pages in a print-out or a subset using its various pseudo-classes.
Live preview Example from MDN
CSS HTML JS
Edit Reset Copy
@page {
size : landscape ;
margin : 2 cm ;
}
section {
page-break-after : always ;
break-after : page ;
}
@media print {
button {
display : none ;
}
}
body {
font-family : "Helvetica" , sans-serif ;
background-color : silver ;
}
article {
width : 100 % ;
}
section {
display : grid ;
background-color : white ;
border-radius : 0.6 rem ;
justify-items : center ;
padding : 1 rem ;
width : 50 % ;
print-color-adjust : exact ;
-webkit-print-color-adjust : exact ;
margin : 0 auto ;
margin-block-end : 1 rem ;
border : 1 px dashed ;
} < button >Print page</ button >
< article >
< section >
< h2 >Header one</ h2 >
< p >Paragraph one.</ p >
</ section >
< section >
< h2 >Header two</ h2 >
< p >Paragraph two.</ p >
</ section >
< section >
< h2 >Header three</ h2 >
< p >Paragraph three.</ p >
</ section >
</ article > const button = document. querySelector ( "button" );
button. addEventListener ( "click" , () => {
window. print ();
}); Syntax @page <page-selector-list>? { <declaration-rule-list> } Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Browser support First browser version supporting @page Chrome 2 Edge 12 Firefox 19 Safari 18.2 Chrome Android 18 Safari iOS 18.2
First version with support, from MDN browser-compat-data.
Descriptors bleed auto | <length> Initial: auto marks none | [ crop || cross ] Initial: none size <length [0,∞]>{1,2} | auto | [ <page-size> || [ portrait | landscape ] ] Initial: auto Specification ↗ MDN reference ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@right-bottom { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@right-middle { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@right-top { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@top-center { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@top-left { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@top-left-corner { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@top-right { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗
No prose in the spec's definition and no MDN page yet: the spec link below is the only description.
Syntax /* for @page */
@top-right-corner { <declaration-list> }; Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Defined for @page
This feature only appears in the context of these properties, functions or types.
Specification ↗