CSS Reference ยท Properties for Special Contexts
The size descriptor
Reference for the size descriptor of the CSS @page rule: set paper size and portrait or landscape orientation for printed pages, with examples.
size is not a property but a descriptor that you can only use inside an @page rule. It sets the dimensions and orientation of the printed page: a named paper such as A4, an explicit width and height, or just landscape or portrait.
@page { size: A4 landscape; }
Try it
The preview cannot print, so it draws mock sheets for each setting. The @page rules are in the code and apply when you print this document.
Syntax
@page { size: auto | <length>{1,2} | [ <page-size> || [ portrait | landscape ] ]; } /* <page-size> = A5 | A4 | A3 | B5 | B4 | JIS-B5 | JIS-B4 | letter | legal | ledger */
- Initial value:
auto - Applies to: page contexts (inside
@page), not elements - Inherited: no
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
auto |
The browser or printer picks the size, usually the default paper chosen in the print dialog. |
One length, 12cm |
A square page with that side. |
Two lengths, 210mm 297mm |
Width then height. |
A4, letter, legal, ... |
A named paper size. Portrait unless an orientation is added. |
portrait / landscape |
Keeps the paper size but sets the orientation. Alone, it uses the default paper size. |
A4 landscape |
A named size combined with an orientation, in either order. |
Usage notes
@pageonly. Usingsizeon an element does nothing. For the element's own dimensions usewidthandheight.- Margins and size. Page
margininside@pagereduces the area available for content; the sheet size itself stays as set. - User control. Browsers may let the print dialog override your size or orientation, and the behavior differs between browsers.
- Use physical units (
mm,cm,in) for page sizes;pxand relative units do not map well onto paper. - Per-section sizes need named pages: define
@page wide { size: landscape }and assign it withpage.
Browser support
Support for size differs between browsers, and some parts of the print dialog can override it. Check a compatibility table and test with print preview or save as PDF.
Related
@pagepage- printing CSS
- Lesson: Print styles