
CSS can apply rules to a printed document, a screen, or another supported output. A media type such as print is different from a media feature such as viewport width.
1. Set media on a stylesheet link
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="print.css" media="print">The general stylesheet applies normally. The second stylesheet’s rules apply during printing when its media condition matches.
2. Use an @media rule in CSS
@media print {
nav, aside, footer { display: none; }
body { color: black; background: white; }
}Use an @media rule for small groups of conditional styles. Use screen or print only when the output type matters. A query without a type can match any applicable output.
3. Add a condition to @import
@import url("print.css") print;Place imports before normal style rules. Use a separate stylesheet link when that makes the dependency easier to discover and maintain.
4. Speech and accessibility
The CSS Speech Module describes properties for aural presentation. Support varies across reading tools. Semantic headings, labels, and reading order are more dependable than trying to control how a particular screen reader speaks. See the CSS Speech specification.
Practice
Create a print stylesheet that hides decorative headers and navigation while preserving the article title, content, and important references. Open print preview and confirm what is included.