CSS Print Stylesheets: Turn Web Pages into Readable Reports and Receipts
A receipt that fits on a phone can waste a sheet of paper on a checkout button. A dashboard can lose its rightmost column in print even though all the numbers are there on screen. A print stylesheet lets you fix both problems in the same HTML document. Open print preview before you change the CSS and find the first piece of information a reader would lose.
A report you can print
Save the example as print-report.html, open it in a browser and choose Print report. Compare the toolbar, the table and the reference at the bottom in the two views. The button opens the browser’s print dialog. The reader chooses the printer or, where available, Save as PDF.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Project status report</title>
<style>
* { box-sizing: border-box; }
body { margin: 0; background: #eef2f5; color: #202c38;
font: 16px/1.5 system-ui, sans-serif; }
.toolbar { padding: 1rem; background: #20354c; color: #fff; }
.toolbar button { padding: .65rem 1rem; cursor: pointer; }
main { max-width: 52rem; margin: 2rem auto; background: #fff;
padding: 2rem; border-radius: .6rem; }
h1, h2 { line-height: 1.2; }
.summary { border: 1px solid #9ba9b7; padding: 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .65rem; border-bottom: 1px solid #a4b0bb;
text-align: left; vertical-align: top; }
a { color: #135d90; }
@page { margin: 14mm; }
@media print {
body { background: white; color: black; font: 11pt/1.35 serif; }
.toolbar { display: none !important; }
main { max-width: none; margin: 0; padding: 0; border: 0; }
h1 { font-size: 20pt; margin-top: 0; }
h2 { font-size: 14pt; break-after: avoid; }
p, li { orphans: 3; widows: 3; }
.summary { border: 1px solid black; break-inside: avoid; }
table { font-size: 10pt; }
thead { display: table-header-group; }
th, td { border-bottom: 1px solid #666; padding: 4pt; }
tr { break-inside: avoid; }
.references a { color: black; text-decoration: underline; }
.references { overflow-wrap: anywhere; }
.references a[href^="https://"]::after {
content: " (" attr(href) ")";
font-size: 9pt;
}
}
</style>
</head>
<body>
<header class="toolbar">
Project documents
<button id="print-report" type="button">Print report</button>
</header>
<main>
<h1>Project status report</h1>
<p>Period: November 2026. Prepared for the project team.</p>
<section class="summary" aria-labelledby="summary-heading">
<h2 id="summary-heading">At a glance</h2>
<p>Two features are complete, one needs review, and one is planned.</p>
</section>
<h2>Milestones</h2>
<table>
<thead><tr><th scope="col">Milestone</th>
<th scope="col">Status</th><th scope="col">Owner</th></tr></thead>
<tbody>
<tr><th scope="row">Navigation</th><td>Complete</td><td>Alex</td></tr>
<tr><th scope="row">Keyboard review</th><td>Complete</td><td>Sam</td></tr>
<tr><th scope="row">Content check</th><td>In review</td><td>Jo</td></tr>
<tr><th scope="row">Launch checklist</th><td>Planned</td><td>Alex</td></tr>
</tbody>
</table>
<section class="references">
<h2>Further reading</h2>
<p>See <a href="https://www.web2generators.com/">Web2Generators</a>
for practical web tools.</p>
</section>
</main>
<script>
document.querySelector('#print-report')
.addEventListener('click', () => window.print());
</script>
</body>
</html>
Give the paper its own margins
The screen layout centers a card with generous padding. On paper that padding would sit inside the printer margins and squeeze the table. The example removes the card padding in @media print and requests a 14 mm margin on each sheet with @page. Only the toolbar disappears. A blanket rule hiding every header would also remove a receipt number if you kept it in a header.
Leave the paper size up to the reader unless you know the stock they’ll use. Compare A4 and US Letter at 100% scale. If the last column disappears, look for a fixed width, a scrolling wrapper or a long unbroken value before reducing the type size.
Keep a table readable on page two
Duplicate the milestone rows until the table spans two pages. The column labels belong in <thead> so a print engine can repeat them. The milestone names are row headers, which also helps people reading the table on screen. Check where a heading lands after you add or remove a row: break-after: avoid asks the browser to keep it with the next block.
Use break-inside: avoid on short summaries and rows. Applying it to a whole table can leave a large gap before the table begins. Even a single row may need to split if it is taller than a page. Try a row with a paragraph of notes as well as the short status values in the sample.
Decide what survives without color or clickable links
The status column says “In review” in text. That still conveys the status when a reader prints in grayscale or disables background graphics. The same principle applies to accessible status colors on screen.
The example prints the destination after a link only in the references section. Choose those references deliberately. A long signed URL can reveal private information and push a report onto an extra page. If a receipt includes a QR code, test its size and blank border on a physical printout. The guest Wi-Fi card tutorial shows how to check a code at its final printed size. For a trial run, make a sample card with the Wi-Fi QR code generator.
Before sending a report, try it with two rows and again with a hundred. Check the last column, the first row on page two and the last line on the final sheet. Then print one copy on the intended printer: its printable area can differ from the PDF preview.