The essentials

Quick reference

One focused task per row. Jump to the related section for complete, working examples.

UseSyntaxExamples
Target print output@media print { nav, .toolbar { display: none; } }View examples
Request paper size@page { size: A4; }View examples
Set page margins@page { margin: 18mm; }View examples
Assign a named page.landscape-table { page: wide; }View examples
Landscape named page@page wide { size: A4 landscape; }View examples
Start on a new pageh1.chapter { break-before: page; }View examples
Keep a block togetherfigure, table { break-inside: avoid; }View examples
Keep ending lines togetherp { orphans: 3; widows: 3; }View examples
Expose external URLsa[href^="http"]::after { content: " (" attr(href) ")"; }View examples
Request exact colors.chart { print-color-adjust: exact; }View examples
Use physical page units@page { margin: 15mm 18mm; }View examples
Repeat table headingsthead { display: table-header-group; }View examples
Expose abbreviation titleabbr[title]::after { content: " (" attr(title) ")"; }View examples

Printed documents fragment continuous content into pages with device-dependent margins, headers, color, and font metrics. Begin with semantic source order, remove interactive-only chrome, expose link destinations where useful, request—not assume—page geometry, and test real browser print previews at multiple paper sizes and scale settings.

Step by step

Detailed examples

01

Replace interaction with a coherent static document

Print styles should not merely hide buttons; they must preserve headings, reading order, labels, data, and outcomes that interactive states otherwise reveal. Use @media print, readable point or rem sizes, physical margins, and ordinary document flow. Avoid fixed-position UI that repeats over page content.

Minimal printable foundation
@media print {
  nav, .toolbar, button, [data-print-hidden] { display: none !important; }
  body { margin: 0; color: #000; background: #fff; font-size: 11pt; line-height: 1.4; }
  main { max-inline-size: none; }
}
Back to quick reference ↑
02

Treat @page dimensions as requests to the output device

@page controls page box size, orientation, and margins, but printer capabilities and user dialog choices can override them. Named pages support special sections such as wide tables. Browser support for margin boxes and generated running headers varies, so critical identity belongs in document content too.

Default portrait and selected landscape pages
@page { size: A4; margin: 18mm; }
@page wide { size: A4 landscape; margin: 14mm; }
.landscape-table { page: wide; }
Back to quick reference ↑
03

Guide breaks without creating blank or clipped content

break-before/after/inside apply to fragmentation contexts, and avoid is a request that may be overridden when a box exceeds a page. widows and orphans govern minimum paragraph lines around breaks. Do not force every heading or component to stay with arbitrarily large content.

Readable chapter and figure breaks
@media print {
  h1.chapter { break-before: page; }
  h2, h3 { break-after: avoid-page; }
  figure, pre, blockquote { break-inside: avoid; }
  p { widows: 3; orphans: 3; }
}
Back to quick reference ↑
04

Expose destinations and hidden context selectively

Printed links cannot be activated, so external destinations may be useful after concise link text. Avoid expanding internal fragments, mailto links, long signed URLs, or every navigation item. Generated content is not a substitute for source content and may not be copied or exposed consistently.

Selective link and abbreviation expansion
@media print {
  main a[href^="https://"]::after { content: " (" attr(href) ")"; font-size: .85em; overflow-wrap: anywhere; }
  a[href^="#"]::after { content: none; }
  abbr[title]::after { content: " (" attr(title) ")"; }
}
Back to quick reference ↑
05

Design for missing backgrounds and grayscale output

Browsers and users may omit backgrounds or alter colors to save ink. print-color-adjust:exact is advisory and should be limited to graphics whose meaning requires exact appearance. Add labels, patterns, borders, or direct values so charts and status remain understandable in monochrome.

Ink-aware chart fallback
@media print {
  .chart { print-color-adjust: exact; }
  .status { color: #000; border: 1px solid currentColor; }
  .status::before { content: attr(data-label) ": "; font-weight: 700; }
  img { max-inline-size: 100%; }
}
Back to quick reference ↑
06

Print data tables and form state as data

Table header groups may repeat across page fragments; prevent rows from splitting where feasible without making large rows unprintable. Interactive inputs can render inconsistently, so reports should include submitted values as text. Ensure signatures, totals, captions, and validation outcomes are present in the document.

Paged table treatment
@media print {
  table { inline-size: 100%; border-collapse: collapse; }
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }
  tr { break-inside: avoid; }
  th, td { border: .5pt solid #555; padding: 4pt; text-align: start; }
}
Back to quick reference ↑

Local code tester

Prepare an article for print

Use browser print preview to inspect page breaks, link destinations, and ink-aware styling.

Runs in your browser
Preview

Sources and further reading

References

Authoritative documentation used to verify and expand this cheat sheet.

  1. World Wide Web ConsortiumCSS Paged Media Module Level 3w3.org
  2. World Wide Web ConsortiumCSS Fragmentation Module Level 3w3.org
  3. World Wide Web ConsortiumCSS Color Adjustment Module Level 1w3.org
  4. World Wide Web ConsortiumMedia Queries Level 4w3.org

Help us improve

Found a typo or missing example?

Tell us what would make this cheat sheet clearer, more complete, or more useful.

Share feedback