Paged media and print
Definition and purpose
A print stylesheet adapts continuous screen content to pages. @media print selects print-specific element rules; @page specifies page-box settings such as size and margin. Print output remains subject to the browser, printer settings and user preferences.
Screen view and page declaration
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @page { size: A4; margin: 16mm; } #a { font-size: 24px; } #b { color: navy; } @media print { #control { display: none; } #b { color: black; } } </style> </head> <body> <main> <h1 id="a">Invoice summary</h1> <p id="b">Amount due: 120</p> <button id="control" type="button">Change view</button> </main> </body></html>The screen keeps the control visible; CSSOM contains the A4 page request.
Syntax and mental model
A4 requests a 210mm by 297mm page size; margin: 16mm requests space around the page area. Hide screen-only controls with display: none in print media, not the information users need. Use break-before: page for a necessary page boundary and avoid unnecessary forced breaks. @page margins differ from the margin of the body. Here CSSOM verifies the page declaration and print-media emulation verifies the element styles; neither demonstrates physical paper output or actual pagination.
Print media adaptation
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @page { size: A4; margin: 16mm; } #a { font-size: 24px; } #b { color: navy; } @media print { #control { display: none; } #b { color: black; } } </style> </head> <body> <main> <h1 id="a">Invoice summary</h1> <p id="b">Amount due: 120</p> <button id="control" type="button">Change view</button> </main> </body></html>When print media is emulated, the button disappears and the amount is black.
Common mistakes
Do not rely on background ink to carry critical information. Check print preview, readable text contrast, page boundaries, repeated headers and margins on the target browser; the user can override many settings.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Fragmentation and breaks. Next lesson: Lists, counters and generated content.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Paged media and print — knowledge check
Five questions on paged media and print.
Which at-rule requests a page size?
Which media query targets print styling?
What dimensions are A4?
What should remain visible in print?
Does print media emulation prove exact paper pagination?