CKTIS / CSS
:first — first printed page
The :first page pseudo-class selects the first page of a document in paged layout, such as printing. Use it in an @page selector to give the first page a separate margin without changing subsequent pages.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
@page :first { margin-top: 40mm; }:first is a page pseudo-class used in the selector of an @page rule. It matches the first page of a document in paged layout, not the first HTML element. It does not replace :first-child or style the first paragraph.
An @page rule without a selector establishes shared page settings. @page :first can change the first page’s settings; for declarations of the same importance and origin, it has greater specificity than plain @page. Its declarations affect the page context, not document elements: do not use this rule to set the text color of the first page.
In the example, margin: 20mm sets all page margins, while margin-top: 40mm changes only the first page’s top margin. break-before: page on .next forces a second page. The expected layout is two A4 pages: the first has a 40mm top margin, the second has a 20mm top margin, and all other margins are 20mm.
Inspect print preview or a PDF, not the ordinary page view. Select A4 and 100% scale, disable browser headers and footers, and do not override CSS margins in the print dialog.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>First page margins</title>
<style>
@page { size: A4; margin: 20mm; }
@page :first { margin-top: 40mm; }
body { margin: 0; font: 16px sans-serif; }
p { margin: 0; }
.next { break-before: page; }
</style>
<p>Page 1</p>
<p class="next">Page 2</p>
</html>Result
Expected print layout: two A4 pages. Page 1 has a 40mm top page margin; Page 2 has a 20mm top page margin. Other page margins are 20mm.
The exact code shown and its expected behavior were checked in an isolated environment. No test of the rendered print layout was documented.