Lesson 36 of 50
cssPrint Stylesheets
8 mins
Course progress72%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 36 of 50
css8 mins
Keep these ideas in mind as you work through the lesson.
A print stylesheet tailors the page for physical paper, removing unnecessary UI, adjusting colors, and re‑flowing content to avoid page‑break issues.
@media print {
/* rules that only apply when printing */
}
@media print {
/* Use a readable type size */
html { font-size:12pt; line-height:1.4; }
/* Hide navigation, footers, and anything that isn’t part of the core content */
nav, .no-print, footer { display:none; }
/* Ensure URLs are visible */
a::after { content:" (" attr(href) ")"; }
/* Avoid orphan headings */
h1, h2 { page-break-after:avoid; }
/* Preserve colours if the printer supports it */
* { color-adjust:exact; }
}
<article class="post">
<h1>Great Article</h1>
<p>Intro …</p>
<section>…</section>
</article>
@media print {
.post { max-width:65ch; margin:auto; }
img { max-width:100%; height:auto; }
}
Serif fonts (Georgia, Times New Roman) improve readability on paper. Use a media query to switch:
@media print { body { font-family:Georgia,serif; } }
a::after rule adds the URL after the link text, guaranteeing that printed documents still convey where a link leads.Print preview in Chrome/Firefox, then Export to PDF to verify layout. Adjust page-break-inside:avoid on large elements like tables or images to prevent awkward splits.