The media queries covered in Section 5.1 target the screen by default, but when a page is printed or "saved as PDF", many on-screen elements (navigation bars, buttons, dark backgrounds) should not appear on paper as they are. @media print is the media type created specifically for this kind of scenario.
@media print
The usage is the same as a normal media query — you just change the media type from the default screen to print:
You can also restrict the media type directly on the <link> tag and split the print styles into a separate file, without affecting the loading priority of the screen styles:
Navigation, buttons, form controls, and video players are usually display: none
Turn dark backgrounds into black-on-white
Force background: #fff; color: #000 to save ink and keep the text readable
Show the real URL of links
a::after { content: " (" attr(href) ")"; } — links cannot be clicked on paper, so printing the URL is what makes them useful
Remove shadows / gradients
Most printers cannot reproduce box-shadow or gradients; removing them avoids gray smudges
Disable fixed positioning
position: fixed/sticky elements may repeat on every page when paginated; usually switch them to static
Page Break Control
You can use break-inside, break-before, and break-after to control how content behaves when it is paginated, keeping a paragraph or a table from being cut in half:
table, figure, .card {
break-inside: avoid; /* try not to break inside this element */
}
h2 {
break-after: avoid; /* keep a heading from being left alone on the last line of a page */
}
.chapter {
break-before: page; /* force each chapter onto a new page */
}
Print Styles Checklist
Pre-publish self-checkRun through the browser's "Print Preview" (rather than guessing) and actually check: whether interactive elements are hidden, whether dark blocks have become large black areas, whether tables/images are cut off abruptly, and whether link URLs need to be printed explicitly. These are the points most often overlooked in print styles, and where problems are easiest to spot all at once.