A simple print style sheet for your website
Web pages do not always survive the trip to paper. Navigation, dark backgrounds, and interactive controls can waste ink or make the printed page hard to read.
One option is to load a separate print style sheet from the HTML <head>:
<link rel="stylesheet" href="main.css" />
<link rel="stylesheet" media="print" href="print.css" />
If you want the main stylesheet to apply only on screen, give both links an explicit media type:
<link rel="stylesheet" media="screen" href="main.css" />
<link rel="stylesheet" media="print" href="print.css" />
For a small number of print changes, keeping them in the existing CSS file is often simpler:
/* on-screen styles */
@media screen {
body {
background: #000;
}
}
/* print styles */
@media print {
body {
background: #fff;
}
}
A real print style sheet will usually do a little more: hide navigation, remove decorative backgrounds, expand the content width, and make link URLs visible when that is useful. Start with the parts that look wrong in the browser’s print preview. There is no need to recreate the whole design on paper.
Enjoyed reading this?
If you found this article helpful, consider supporting my writing. Every little bit helps keep this blog going.
Related articles
- When CSS Layout Order Stops Matching the HTML
Keep Grid and Flexbox layouts aligned with the HTML order so keyboard focus and screen reader reading do not jump around the page.
- Show Form Errors After Interaction With :user-invalid
Use :user-invalid and :user-valid to style native HTML validation states without marking untouched fields as errors.
- Expandable sections with HTML details and summary
Build simple accordions and disclosure sections with the native HTML details and summary elements.