CKTIS / CSS
@page — printed-page size and margins
The @page rule controls the size, orientation, margins, and margin boxes of pages produced by a paged-media formatter.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
@page <page-selector-list> {
<page-body>
}@page <page-selector-list>? { <declaration-rule-list> } targets a page box, not a DOM element. The size descriptor selects a named sheet size, orientation, or pair of dimensions, while margin properties establish the content area. A selector can contain a name assigned with the page property and page pseudo-classes such as :left, :right, :first, or :blank.
A named rule applies only to fragments assigned that page name. :left and :right depend on binding direction rather than universally meaning odd or even page numbers. A single dimension is invalid for size; two explicit dimensions must be positive. Declarations unsupported in page context are ignored and do not style an ordinary element.
Nested page-margin rules can generate headers, footers, or page counters. Their boxes occupy the page margins, so a small margin constrains their available area. The example defines a named left page sized 100mm 50mm and reads the real CSSPageRule, selector, size, and margin; the complete layout effect appears only in paged media.
Examples
const style = document.createElement('style');
style.textContent = '@page chapter:left { size: 100mm 50mm; margin: 10mm; }';
document.head.append(style);
const rule = style.sheet.cssRules[0];
console.log('rule=' + rule.constructor.name + '; selector=' + rule.selectorText + '; size=' + rule.style.getPropertyValue('size') + '; margin=' + rule.style.getPropertyValue('margin'));Result
rule=CSSPageRule; selector=chapter:left; size=100mm 50mm; margin=10mm
The @page rule controls the size, orientation, margins, and margin boxes of pages produced by a paged-media formatter.