CSS Reference ยท Media Queries and Features
The print and screen media types
Reference for the CSS print, screen and all media types: target printed pages or screens, the legacy types, combine with features, with examples and tips.
A media type names the broad category of output your CSS is for. Today only a few types matter: screen (displays), print (paper and print preview, including save-as-PDF) and all (every type, and the default when you write no type). Types come before features in a media query and let you write CSS that applies only when printing.
@media print { nav, .ads { display: none; } }
Try it
On screen, this page shows a navigation bar and a colored card. Open the print preview of the page and the navigation disappears and the card turns plain. (The panel below also says which type is active in the preview.)
Syntax
@media screen { /* ... */ } @media print { /* ... */ } @media all { /* ... */ } @media screen and (min-width: 600px) { /* type plus feature */ } @media not print { /* everything except print */ } @media only screen and (min-width: 600px) { /* legacy hide-from-old-browsers */ }
Values
| Value | Description |
|---|---|
all |
All devices. This is the default. |
screen |
Computer, phone and similar screens. |
print |
Paged output: printed documents and print preview. |
The older types tty, tv, projection, handheld, braille, embossed, aural and speech are deprecated. Modern browsers treat them as matching nothing, so do not use them.
Usage notes
- A separate stylesheet.
<link rel="stylesheet" href="print.css" media="print">loads a print-only file without blocking page rendering. - What to change in print. Hide navigation, ads, buttons and video; switch to black text on white; set sensible margins with
@page; avoid breaking images and headings across pages withbreak-insideandbreak-after. - Show link addresses.
a[href^="http"]::after { content: " (" attr(href) ")"; }inside@media printhelps readers of paper. - Backgrounds. Browsers often skip background colors when printing, to save ink. Do not rely on them for meaning.
onlyandnot.notnegates the whole query, andonlyis a leftover from the days of old browsers; you can skip it today.- Units. In print, use
pt,cmormmwhere it helps, andinfor physical sizes.
Browser support
The all, screen and print types are supported in every browser; the deprecated types are not worth using.
Related
@mediaโ the at-ruleresolutionโ includes print-friendly units- Lessons: Print Styles, Media Queries