CSS @top-right-corner At-Rule
The @top-right-corner at-rule defines generated content in the upper-right corner margin box of printed pages.
It is nested inside @page and can display short labels, page information, or other print-only content.
Syntax
@page {
margin: 20mm;
@top-right-corner {
content: "PDF";
font-size: 9pt;
}
}
Place @top-right-corner inside an @page rule. Its declarations style generated content in the corner box where the top and right page margins meet.
How @top-right-corner Works
The box is generated during paged-media layout. It is not an HTML element, and its content does not appear in the normal browser viewport.
Unlike @top-right, which occupies a segment along the top margin, the corner box occupies the intersection of the top and right margins.
Corner Position and Dimensions
@page {
size: A4;
margin: 25mm 20mm;
@top-right-corner {
content: "A";
text-align: center;
vertical-align: middle;
}
}
The top and right page margins determine the available corner area. The exact placement depends on the print engine, paper size, and page setup.
Styling Corner Content
@page {
margin: 20mm;
@top-right-corner {
content: "CSS";
font: bold 9pt Arial, sans-serif;
color: #175d91;
background: #eaf3fb;
border: 1px solid #9dbbd1;
text-align: center;
vertical-align: middle;
}
}
Applicable CSS properties can style the margin box. Keep labels short so they fit in the limited corner space. Print color and background output may depend on browser print settings.
Related Top Margin Boxes
@page {
margin: 20mm;
@top-left { content: "Guide"; }
@top-center { content: "CSS Reference"; }
@top-right { content: counter(page); }
@top-right-corner { content: "PDF"; }
}
These boxes have different positions. @top-right is part of the top edge, while @top-right-corner is at the upper-right corner. counter(page) supplies the current printed page number.
Page-Specific Corner Labels
@page :first {
@top-right-corner {
content: "START";
}
}
@page :right {
@top-right-corner {
color: #175d91;
}
}
Page selectors can adjust margin content on the first page or on right-hand pages. When rules overlap, the normal page-rule cascade determines the final values.
@top-right-corner Example
The following example adds a compact label to the upper-right corner of each printed page.
HTML
<h1>Printable CSS Guide</h1>
<p>Use Print Preview to see the corner label.</p>
CSS
@page {
size: A4;
margin: 20mm;
@top-right-corner {
content: "CSS";
font: bold 9pt Arial, sans-serif;
color: #175d91;
text-align: center;
vertical-align: middle;
}
}
Print Preview: Open the browser print dialog or print to PDF in a supporting browser. The label appears in the top-right corner margin box. A normal Browser Result cannot demonstrate print-only margin content.
Browser Support
CSS page-margin boxes work in current versions of several major browsers, but older browsers and some print engines may omit them. Check current compatibility information at Can I Use? . Search for CSS page margin boxes and verify the actual print output.
Specifications
The rule is specified in CSS Paged Media Module Level 3.
