CSS Print Stylesheet
Optimize web pages for printing using CSS print media queries with page breaks and display adjustments for paper output.
Code
@media print {
body { font-size: 12pt; color: black; }
.no-print { display: none; }
h1 { page-break-before: always; }
a::after { content: " (" attr(href) ")"; }
}CSS Print Stylesheet
Optimize web pages for printing using CSS print media queries with page breaks and display adjustments for paper output.
Code
@media print {
body { font-size: 12pt; color: black; }
.no-print { display: none; }
h1 { page-break-before: always; }
a::after { content: " (" attr(href) ")"; }
}
Explanation
@media print applies rules only when the page is printed, hiding navigation and controlling page breaks. Expected behavior: backgrounds are dropped by default and the printed sheet shows the content column. Caveat: users can override background printing, and break-inside: avoid is a hint that engines may ignore on very tall blocks.
Interactive Tools for This Topic
CSS Flexbox PlaygroundInteractively test CSS flexbox container and item properties with a live preview. Adjust justify-content, align-items, flex-direction, and flex-grow to see layout changes.CSS Grid PlaygroundExperiment with CSS grid layout properties interactively. Define columns, rows, gaps, and areas while watching the grid template update in a live visual preview.Aspect Ratio CalculatorSimplify a width-to-height ratio, show its decimal value, and derive a matching height for a new width.Border Radius PreviewPreview four-corner border-radius values on a live box and copy the generated shorthand border-radius CSS declaration.
Report a problem with this exampleOpens a pre-filled issue on GitHub.