Web development
Make an article easier to print
Add print-specific CSS to remove repeated navigation and preserve readable article content. Check code blocks, page breaks, and link meaning in an actual print preview.
Worked example
HTML example · save as example.html and open in a browser
<style>
@media print {
nav,aside,.site-footer{display:none}
body{background:white;color:black}
main{display:block;max-width:none}
pre{white-space:pre-wrap;overflow-wrap:anywhere}
h2,h3{break-after:avoid}
}
</style>
<main><h1>Reference notes</h1><p>Content remains available in print.</p></main>How it works
Print rules adapt the reading layout to paper or PDF rather than reproducing every screen control. Wrapping code prevents long lines from being clipped. Keeping headings near following content reduces isolated titles at the bottom of a page.
Limits and mistakes
Browser pagination varies, and break rules are best-effort. Do not hide every aside if some contain essential warnings or definitions. Verify the actual article, including tables and examples, before claiming a polished printable version.
Check the result
Open print preview in a supported browser and inspect multiple pages. Confirm all substantive content remains, text is legible, and no wide example is cut off.
Sources
Reference documentation for the behavior used in this guide: