media

@page

Styles the page box used when printing or generating paged media, controlling size, margins, and margin boxes like headers and footers. Selectors like :first, :left, :right, and named pages let you target specific pages.

@page [<page-selector>] { <descriptors> }

Common conditions / descriptors

Descriptor Purpose
size Page dimensions and orientation, e.g. A4 landscape
margin Printable margins around the page box
:first Target only the first page
:left / :right Target left- or right-facing pages in duplex output
:blank Style blank pages inserted by forced breaks
@top-center / @bottom-right Margin box regions for running headers/footers

Examples

@page {
  size: A4;
  margin: 20mm;
}

Set paper size and uniform margins for print

@page :first {
  margin-top: 40mm;
}

Larger top margin on the cover page

@page {
  @bottom-center { content: counter(page) ' / ' counter(pages); }
}

Page numbers in the bottom margin (paged-media UAs)

@media print {
  @page { size: letter; margin: .5in; }
  a::after { content: ' (' attr(href) ')'; }
}

Print-specific page setup plus link URL annotation

Gotcha

Browsers implement only a subset of the Paged Media spec — margin boxes and named pages work best in PDF-generation engines. Only a limited set of properties (size, margin, orphans, widows, etc.) are honored inside @page.

Related at-rules

← All CSS at-rules · CSS properties · CSS selectors