</> ConvertAtlas Developer Tools
Level 3 · Advanced — Modern CSS Lesson 39 Advanced 12 min

Print Styles and Special Media

Print stylesheets and other media types for documents that look right on paper.

People print invoices, articles and receipts more than you think — and by default web pages print badly, with navigation bars and dark backgrounds wasting ink. A small print stylesheet makes documents look professional on paper.

The @media print query

Styles inside <code>@media print</code> apply only when printing (or saving to PDF). Use it to strip away screen-only chrome: navigation, sidebars, ads, buttons.

css
@media print {
  .nav, .sidebar, .footer, .ad { display: none; }
  body { color: #000; background: #fff; }
}

Controlling page breaks

Use <code>break-inside: avoid</code> to stop an element splitting across pages (great for cards and figures), and <code>break-before</code>/<code>break-after</code> to force breaks before sections like new chapters.

css
.card { break-inside: avoid; }
h2 { break-after: avoid; } /* keep heading with its content */

Save ink and show URLs

Switch dark themes to black-on-white for print to save ink. A classic trick reveals link destinations on paper using a pseudo-element, since printed links cannot be clicked.

css
@media print {
  a::after { content: ' (' attr(href) ')'; font-size: .9em; }
}

Other media types and features

Beyond <code>print</code> and <code>screen</code>, media features let you adapt to capabilities: <code>prefers-color-scheme</code>, <code>prefers-reduced-motion</code>, <code>hover</code> (does the device have a hover-capable pointer?) and <code>orientation</code>. They let CSS respond to the real device, not just its width.

Common mistake
Don't
/* no print styles */
Do
@media print { .nav { display: none; } body { color:#000 } }

Forgetting print entirely, so users get pages with navigation, dark backgrounds and no link context. A short print stylesheet fixes it.

Best practice

Add a small @media print block to content-heavy pages: hide chrome, force black-on-white, avoid breaking cards across pages, and reveal link URLs. Test with your browser's print preview.

Try it yourself

Write an @media print block that hides a nav and footer, sets black text on white, and prevents cards breaking across pages with break-inside: avoid. Check it in print preview.

Quick quiz

1. When do @media print styles apply?

2. What stops an element splitting across pages?

3. Which media feature detects a hover-capable pointer?

Key takeaways
  • @media print styles apply when printing or saving to PDF.
  • Hide chrome, force black-on-white, and reveal link URLs for print.
  • Control page breaks with break-inside/break-before/after.
  • Media features adapt CSS to device capabilities, not just width.