CSS @top-left-corner At-Rule
The @top-left-corner at-rule defines generated content in the top-left corner margin box of a printed page.
It is a page-margin at-rule nested inside @page. Authors can use it for corner labels and decorations, page numbers, or short labels that repeat across printed pages. Its content appears in print layout, not in the normal browser viewport.
@top-left-corner Syntax
@page {
margin: 20mm;
@top-left-corner {
content: "Guide";
}
}
Place @top-left-corner inside an @page rule. The content property supplies the generated text, counter, or other supported content for that margin box. The at-rule cannot be used as an ordinary top-level style rule.
How @top-left-corner Works
During printing, the browser creates page boxes with a content area and surrounding margins. The @top-left-corner rule describes a box in the intersection of the top and left page margins. Its generated content can repeat on every applicable printed page without adding repeated HTML elements.
Page-margin boxes are separate from the browser’s own print headers and footers. If browser-provided headers are enabled, they may compete for space or visually overlap with CSS-generated content.
Page-Margin Placement
The corner box occupies the upper-left intersection of the top and left page margins. Increase the top and left margins if the label needs additional room. Unlike the top-left edge box, it is anchored at the corner.
@page {
size: A4;
margin: 25mm 20mm 20mm 25mm;
@top-left-corner {
content: "Guide";
}
}
The size declaration sets the intended paper size, while margin reserves space around the page content. The final result also depends on printer settings and the browser’s print engine.
Styling the Margin Box
Page-margin boxes support generated content and applicable CSS properties such as font, color, background, border, and alignment. Choose a legible font size and sufficient contrast for print.
@page {
margin: 25mm;
@top-left-corner {
content: "Guide";
font: 9pt Arial, sans-serif;
color: #175d91;
text-align: center;
vertical-align: middle;
}
}
Some properties may render differently in different print engines. Always inspect the generated PDF or printed sheet rather than assuming the screen view reflects the output.
Page Selectors
Use page pseudo-classes such as :first, :left, and :right to vary the margin content on selected printed pages.
@page {
@top-left-corner {
content: "Guide";
}
}
@page :first {
@top-left-corner {
content: "";
}
}
In this example, the default label is omitted from the first page. Whether left- and right-hand pages are used depends on the document’s pagination and page progression.
Related Margin Boxes
The related @top-left and @left-top boxes occupy other positions around the page. You can combine several margin boxes in the same @page rule to build a print header or footer.
@page {
margin: 25mm;
@top-left-corner {
content: "CSS Guide";
}
@bottom-right {
content: counter(page);
}
}
The counter(page) expression generates the current printed page number. To show the total page count, check support for counter(pages) in the target print engine.
@top-left-corner Example
This example displays a short label in the top-left corner margin box of a printed page and a page number in the bottom-right margin. Use Print Preview to inspect the result.
HTML
<h1>CSS Print Guide</h1>
<p>Open Print Preview to see the generated margin content.</p>
<p>Add enough text to create multiple pages.</p>
CSS
@page {
size: A4;
margin: 25mm;
@top-left-corner {
content: "CSS Print Guide";
font: bold 9pt Arial, sans-serif;
color: #175d91;
}
@bottom-right {
content: counter(page);
font: 9pt Arial, sans-serif;
}
}
Print Preview: In a supporting browser, the label appears in the top-left corner margin box of a printed page. The page number appears at the bottom-right. Because this feature only appears during pagination, an ordinary on-screen Browser Result would not demonstrate it accurately.
Browser Support
CSS page-margin boxes are supported in current versions of several major browsers, but older browsers and some print engines may ignore them. Support for particular styling properties may also vary.
For current compatibility, visit Can I Use? and search for CSS page margin boxes. Test the actual print or PDF output in the browsers you intend to support.
Specifications
The @top-left-corner page-margin at-rule is defined in CSS Paged Media Module Level 3.
