Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

Print styles

Print styles adapt a document for printing or print preview using @media print. They can hide navigation, change text presentation, and specify page margins and preferences for breaking content across pages.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

@media print {
  /* Rules for printed output */
  @page { margin: 20mm; }
  .no-print { display: none; }
  article { break-inside: avoid; }
}

Print styles (print styles) are CSS rules intended for printed output, not a separate language. An @media print block applies when the browser renders the document for the print medium, for example in print preview. Rules outside media queries still participate in the cascade; print styles do not automatically replace the entire stylesheet.

In the example, .no-print { display: none; } removes navigation from the print layout, while body { color: black; } changes the text color. Order, specificity, and the other cascade rules still resolve conflicts. Merely placing a declaration inside @media print does not increase its priority.

The @page rule describes the page box, such as its margins; it is not an HTML element selector. The break-inside: avoid property discourages splitting article across fragments, including pages. It does not guarantee keeping arbitrarily long content on one page: a forced break or insufficient space may require splitting the element.

Check the result in the target browser’s print preview. Paper size, scaling, and print settings can affect the result, so do not assume identical pagination in every environment. A feature’s presence in a specification does not confirm support in a particular browser version.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Print styles demo</title>
<style>
  body { font: 16px sans-serif; color: navy; }
  @media print {
    @page { margin: 20mm; }
    body { color: black; }
    .no-print { display: none; }
    article { break-inside: avoid; }
  }
</style>
<nav class="no-print">Navigation</nav>
<article>
  <h1>Report</h1>
  <p>Keep this content in the printed document.</p>
</article>
</html>

Result

Screen: Navigation, Report, and the paragraph appear in navy. Print preview: Navigation is absent; Report and the paragraph appear in black. CSS requests 20mm page margins and avoidance of breaks inside article; final pagination depends on print settings and available space.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources