CSS @right-top At-Rule

The @right-top at-rule generates content in the upper portion of the right margin of a printed page.

It is a page-margin at-rule nested inside @page. Use it for running labels or other repeated print-only information.

@right-top Syntax

@page {
  margin: 25mm;
  @right-top {
    content: "Section A";
  }
}

Place @right-top inside @page. Its content declaration supplies generated content for the upper position on the right page margin.

How @right-top Works

The page-margin box is generated during print layout, not in the normal webpage viewport. It repeats on applicable printed pages without requiring a corresponding HTML element.

The box is positioned in the upper part of the right margin, above @right-middle and @right-bottom.

Position and Page Margins

@page {
  size: A4;
  margin: 20mm 30mm 20mm 20mm;
  @right-top {
    content: "CSS Guide";
  }
}

The larger right margin provides room for the label. Available space depends on page size, margins, and neighboring margin boxes.

Styling Margin Content

@page {
  margin-right: 30mm;
  @right-top {
    content: "CSS Reference";
    font: bold 10pt Arial, sans-serif;
    color: #175d91;
    writing-mode: vertical-rl;
  }
}

Page-margin boxes accept generated content and applicable styling. The writing-mode declaration requests vertical text, but print engines may differ in their rendering.

The right edge provides @right-top, @right-middle, and @right-bottom. They occupy different positions, so they can be combined.

@page {
  margin-right: 30mm;
  @right-top { content: "Chapter"; }
  @right-middle { content: "Reference"; }
  @right-bottom { content: counter(page); }
}

counter(page) displays the current printed page number.

Page Selectors

@page :right {
  @right-top {
    content: "Odd-page note";
  }
}

The :right page pseudo-class selects right-hand pages in a paged document. Which pages count as right-hand pages depends on pagination and writing direction.

@right-top Example

This example puts a running label near the top of the right page margin.

HTML

<h1>CSS Reference</h1>
<p>Open Print Preview to see the margin label.</p>

CSS

@page {
  size: A4;
  margin: 20mm 30mm 20mm 20mm;
  @right-top {
    content: "CSS Reference";
    writing-mode: vertical-rl;
    font: bold 10pt Arial, sans-serif;
    color: #175d91;
  }
}

Print Preview: Open the browser print dialog or print to PDF. In a supporting browser, the label appears in the upper part of the right margin. A normal Browser Result cannot display this print-only feature.

Browser Support

CSS page-margin boxes are supported in recent versions of major browsers, but older browsers and some print engines may omit them. Check Can I Use? for CSS page margin boxes and test printed output.

Specifications

The rule is defined in CSS Paged Media Module Level 3.

CSS Paged Media Module Level 3