@page
The @page
CSS at-rule is used to modify some CSS properties when printing a document.
Syntax
@page { margin: 1cm; } @page :first { margin: 2cm; }
Descriptors
size
-
Specifies the target size and orientation of the page box’s containing block. In the general case, where one page box is rendered onto one page sheet, it also indicates the size of the destination page sheet.
Description
You can't change all CSS properties with @page
. You can only change the margins, orphans, widows, and page breaks of the document. Attempts to change any other CSS properties will be ignored.
The @page
at-rule can be accessed via the CSS object model interface CSSPageRule
.
Note: The W3C is discussing how to handle viewport-related <length>
units, vh
, vw
, vmin
, and vmax
. Meanwhile do not use them within a @page
at-rule.
Formal syntax
@page <page-selector-list> { <page-body> }where
<page-selector-list> = [ <page-selector># ]?
<page-body> = <declaration>? [ ; <page-body> ]? | <page-margin-box> <page-body>where
<page-selector> = <pseudo-page>+ | <ident> <pseudo-page>*
<page-margin-box> = <page-margin-box-type> '{' <declaration-list> '}'where
<pseudo-page> = : [ left | right | first | blank ]
<page-margin-box-type> = @top-left-corner | @top-left | @top-center | @top-right | @top-right-corner | @bottom-left-corner | @bottom-left | @bottom-center | @bottom-right | @bottom-right-corner | @left-top | @left-middle | @left-bottom | @right-top | @right-middle | @right-bottom
Examples
@page pseudo-class examples
Please refer to the various pseudo-classes of @page
for examples.
Specifications
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
@page |
2 |
12 |
19 |
8 |
6 |
No |
37 |
18 |
19 |
14 |
No |
1.0 |
page-orientation |
85 |
85 |
No |
No |
71 |
No |
85 |
85 |
No |
60 |
No |
14.0 |
size |
15 |
79 |
No |
No |
15 |
No |
37 |
18 |
No |
14 |
No |
1.5 |
See also
- See the [META] CSS Paged Media Module Level 3 ticket in Bugzilla for tracking progress on the subject (page-based counters, etc.)
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/@page