CSS Reference ยท Properties for Special Contexts
The page property
Reference for the CSS page property: assign elements to named pages defined with @page, so wide tables can print landscape while text stays portrait.
The page property assigns an element to a named page type. You define the page type with @page name { ... } and then point elements at it with page: name. When printing, the browser starts a new page whenever the page type changes, and uses that page type's size, margins and orientation.
The classic use is a document that is portrait throughout, except for one wide table that prints on a landscape page.
@page wide { size: landscape; } table.report { page: wide; }
Try it
A preview cannot print, so this page draws two mock sheets to show what the print result looks like: a portrait sheet for the default page and a landscape sheet for the wide page. Use print preview on your own document to see the real thing.
Syntax
page: auto | <custom-ident>;
- Initial value:
auto - Applies to: block-level elements
- Inherited: no, but the value of an element with
autois taken from its parent for the purpose of choosing pages - Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
auto |
Uses the page type of the parent (the default page at the root). |
<custom-ident> |
The name of a page type declared with @page name { ... }. The name is case-sensitive and must not be auto. |
Usage notes
- Forced breaks. Changing the page type between siblings forces a page break before and after the element. Plan it to avoid blank pages.
- Only some properties apply. Named
@pagerules mostly controlsize, margins and margin boxes; not every descriptor is available everywhere. - Block-level only. Put
pageon blocks such assection,divortable; inline elements do not start pages. - Browsers differ on printing. Test in print preview or by saving as PDF in each browser you care about. Orientation settings in the print dialog may override your page size.
- Screen is unaffected. The property does not change how the page looks on screen.
Browser support
Support for named pages exists in some current browsers but is not universal; check a compatibility table and test your print output.
Related
@pagesize- printing CSS
- Lesson: Print styles