CSS page Property
The CSS page property assigns an element to a named page type when a document is printed or displayed using paged media.
Named pages are defined using the @page at-rule. They allow different sections of a document to use different page sizes, orientations, or margins without changing the layout of the document on screen.
page Syntax
The page property accepts the keyword auto, a custom identifier representing a named page, or a CSS-wide keyword.
Basic Syntax
selector {
page: report;
}
This assigns the element to a named page called report.
Default Value
selector {
page: auto;
}
The auto value allows the element to use the named page of its containing context or the default page when no named page applies.
Named Page Values
.cover {
page: cover;
}
.chapter {
page: chapter;
}
.appendix {
page: appendix;
}
Each custom identifier represents a named page type that can be styled using a corresponding @page rule.
CSS-Wide Keywords
.section {
page: initial;
}
.section {
page: inherit;
}
.section {
page: unset;
}
.section {
page: revert;
}
.section {
page: revert-layer;
}
CSS-wide keywords control how the property's value is initialized, inherited, or resolved through the cascade.
Property Values
| Value | Description |
|---|---|
auto |
Uses the applicable page context or default page type. |
<custom-ident> |
Assigns the element to a named page identified by a custom name. |
initial |
Resets the property to its initial value of auto. |
inherit |
Uses the computed value from the parent element. |
unset |
Resets the property to its initial value because the property is not inherited. |
revert |
Reverts the property according to CSS cascade origin rules. |
revert-layer |
Reverts the property according to CSS cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto |
| Inherited | No |
| Applies to | Elements that generate boxes, subject to paged-media fragmentation rules |
| Computed value | As specified |
| Animation type | Discrete |
| Media | Paged media |
| Related at-rule | @page |
| Percentages | Not applicable |
Valid Values
.section {
page: auto;
}
.section {
page: report;
}
.section {
page: landscapePage;
}
.section {
page: appendix-page;
}
Invalid Values
.section {
page: 20px;
}
.section {
page: 50%;
}
.section {
page: "report";
}
.section {
page: report appendix;
}
The property does not accept lengths, percentages, quoted strings, or multiple page names in a single declaration.
How It Works
The page property associates an element with a named page type. The matching @page rule defines the page box used when that content is printed.
Assigning a Named Page
.report-section {
page: report;
}
This tells the browser that the report section should use the named page type report.
Defining the Named Page
@page report {
size: A4;
margin: 20mm;
}
The @page rule defines an A4 page with 20-millimeter margins for content assigned to report.
Combining the Rules
@page report {
size: A4;
margin: 20mm;
}
.report-section {
page: report;
}
When the document is printed, the report section uses the page settings associated with the named page, subject to browser support and print settings.
Multiple Named Pages
@page portraitPage {
size: A4 portrait;
margin: 20mm;
}
@page landscapePage {
size: A4 landscape;
margin: 15mm;
}
.portrait-section {
page: portraitPage;
}
.landscape-section {
page: landscapePage;
}
Different sections can request different page orientations within the same printed document.
Named Pages and @page Rules
The page property and @page at-rule serve different purposes.
| CSS Feature | Purpose |
|---|---|
page |
Assigns an element to a named page type. |
@page |
Defines the dimensions, margins, and supported page-specific formatting for printed pages. |
Creating a Cover Page
@page cover {
size: A4;
margin: 30mm;
}
.cover {
page: cover;
}
The cover section requests its own page settings.
Creating a Landscape Page
@page wide {
size: landscape;
margin: 15mm;
}
.wide-content {
page: wide;
}
This is useful for wide tables, diagrams, and reports that need more horizontal space when printed.
Using a Default Page
@page {
size: A4;
margin: 20mm;
}
@page wide {
size: A4 landscape;
margin: 15mm;
}
.wide-content {
page: wide;
}
The unnamed @page rule provides general page settings. The named rule provides settings for content assigned to wide.
Matching Names
The identifier in the page declaration must match the intended named @page rule.
@page appendix {
margin: 25mm;
}
.appendix {
page: appendix;
}
Custom page names are CSS identifiers, not strings. They should be descriptive and consistent throughout the stylesheet.
Named Pages and Page Breaks
Changing the named page type between consecutive sections normally requires a page break so the next section can begin on a page using its assigned page settings.
Changing Page Types
@page portraitPage {
size: A4 portrait;
}
@page landscapePage {
size: A4 landscape;
}
.introduction {
page: portraitPage;
}
.data-table {
page: landscapePage;
}
When the printed document transitions from the introduction to the data table, the browser can create a page break to apply the new page type.
Explicit Page Breaks
.new-chapter {
break-before: page;
}
The break-before property explicitly requests a page break before the element.
Combining Named Pages and Breaks
.chapter {
page: chapterPage;
break-before: page;
}
This assigns the chapter to a named page and requests a new page before the chapter begins.
Avoiding Breaks Within Content
.print-card {
break-inside: avoid;
}
The break-inside property requests that the card remain together when possible. It does not guarantee that content larger than the available page area will fit on one page.
Legacy Page Break Properties
.chapter {
page-break-before: always;
}
The older page-break-before, page-break-after, and page-break-inside properties are retained for compatibility. Modern CSS generally uses break-before, break-after, and break-inside.
Using page With Print Media
The page property is intended for paged layouts. It does not change the appearance of ordinary screen-based layouts.
Print-Specific Rules
@media print {
.report {
page: reportPage;
}
}
@page reportPage {
size: A4;
margin: 20mm;
}
The named page assignment applies when the document is printed. The @page rule defines the corresponding page formatting.
Screen and Print Layouts
.report {
max-width: 900px;
margin-inline: auto;
}
@media print {
.report {
max-width: none;
margin: 0;
page: reportPage;
}
}
@page reportPage {
size: A4;
margin: 20mm;
}
The report can use a centered layout on screen and a named page format when printed.
Print Preview
Use the browser's Print Preview feature to inspect page sizes, margins, orientation, and page breaks. Results can vary depending on the browser, printer, paper selection, and print settings.
Important Limitation
Browsers may restrict or override some requested page settings. A named page does not guarantee that every printer or PDF output will use the exact requested dimensions.
page Property Example
The following example assigns different page formats to a report cover, main content, and a wide data table.
HTML Example
<div class="print-document">
<section class="report-cover">
<h2>Annual Report</h2>
<p>Report cover and introduction.</p>
</section>
<section class="report-content">
<h2>Report Summary</h2>
<p>Main report content.</p>
</section>
<section class="report-table">
<h2>Data Overview</h2>
<p>A wide table or chart can use landscape pages.</p>
</section>
</div>
CSS Example
@page coverPage {
size: A4 portrait;
margin: 30mm;
}
@page contentPage {
size: A4 portrait;
margin: 20mm;
}
@page tablePage {
size: A4 landscape;
margin: 15mm;
}
.report-cover {
page: coverPage;
}
.report-content {
page: contentPage;
}
.report-table {
page: tablePage;
}
@media print {
.report-content,
.report-table {
break-before: page;
}
}
Screen Preview
The following preview illustrates the three report sections. The colored boxes are ordinary screen elements, not a simulation of printed page dimensions.
Annual Report
Named page: coverPage
Report Summary
Named page: contentPage
Data Overview
Named page: tablePage
The actual page sizes and orientations are applied during printing, not in the screen preview above.
Expected Print Behavior
| Section | Named Page | Requested Format |
|---|---|---|
| Report Cover | coverPage |
A4 portrait, 30mm margins |
| Report Summary | contentPage |
A4 portrait, 20mm margins |
| Data Overview | tablePage |
A4 landscape, 15mm margins |
Print Preview can be used to verify how the browser applies these named page settings.
Accessibility Considerations
Named pages affect printed layout rather than the semantic meaning of HTML content. Accessible document structure remains important for both screen and print use.
Preserve Document Structure
Use appropriate headings, sections, tables, and other semantic HTML elements. The page property does not provide document structure or accessibility information.
Maintain Logical Reading Order
Keep content in a meaningful source order. Printed page changes should not make the document difficult to follow.
Avoid Splitting Important Content
@media print {
figure,
.important-note {
break-inside: avoid;
}
}
Where practical, keep related content together across page boundaries.
Maintain Readable Print Sizes
Choose page dimensions and margins that leave enough space for readable text, tables, and images.
Test Printed Output
Review print output for clipped text, missing information, unexpected blank pages, and content that becomes difficult to read.
Important Consideration
The page property does not automatically make exported PDF documents accessible. PDF accessibility depends on the document structure and the capabilities of the PDF creation process.
Common Mistakes
Confusing page With @page
The page property assigns a page name to content. The @page at-rule defines formatting for that named page.
Using a Quoted String
.report {
page: "reportPage";
}
Page names are CSS identifiers, not quoted strings.
Using a Length Value
.report {
page: 20px;
}
The page property does not accept length values. Page dimensions belong in an @page rule.
Using a Percentage
.report {
page: 50%;
}
Percentages are not valid values for the page property.
Using a Mismatched Page Name
@page reportPage {
size: A4;
}
.report {
page: reportsPage;
}
The identifiers do not match. The intended reportPage formatting will not be selected by the reportsPage declaration.
Expecting Screen Layout Changes
The page property is intended for paged media. It does not create visible page boundaries in an ordinary scrolling webpage.
Assuming Every Browser Supports Every Feature
Support for named pages, page sizing, page margin boxes, and other paged-media features varies. Test the exact features needed by the project.
Ignoring Print Settings
Browser print settings and printer capabilities can affect the final paper size, orientation, and margins.
Forgetting Page Breaks
Named page changes can cause page breaks, but explicit breaks may still be needed to organize chapters or sections as intended.
Important Considerations
Keep the following points in mind when using the page property:
- It assigns an element to a named page type.
- It is intended for paged media, especially printed documents.
- Its initial value is
auto. - The property is not inherited.
- Named page values use CSS custom identifiers.
- Page names must not be enclosed in quotation marks.
- The
autokeyword is reserved and cannot serve as a custom page name. - The
@pageat-rule defines named page formatting. - The
pageproperty does not directly set page size or margins. - Different named pages can request different page sizes.
- Different named pages can request portrait or landscape orientation.
- Changing named page types can cause page breaks.
- The
break-beforeandbreak-afterproperties provide additional page-break control. - The
break-insideproperty can help keep related content together. - Named page formatting does not create visible page boundaries in normal screen layouts.
- Print Preview is useful for testing named page behavior.
- Browser support for paged-media features varies.
- Printer settings may override requested page dimensions or margins.
- Named pages can be useful for reports, manuals, invoices, and other printed documents.
- Semantic HTML and logical reading order remain important.
- Printed content should be checked for clipping and unexpected blank pages.
- The property does not automatically make generated PDFs accessible.
Browser Support
The CSS page property has Newly available baseline support in modern browsers. Support for assigning named pages has improved, but older browser versions may not recognize the property.
Support for individual @page features, including page sizing and margin boxes, should be checked separately. Printing behavior may also depend on browser and printer settings.
For current compatibility information, visit Can I Use? and search for the CSS page property.
Specifications
The page property is defined in CSS Paged Media Module Level 3.
CSS Paged Media Module Level 3
The specification describes named pages, page selection, page boxes, and their relationship to paged-media layout.
For additional documentation and examples, consult MDN Web Docs.
