Color scheme

Print Stylesheets

When someone prints a web page, the browser strips away the interactive shell and lays the content onto a fixed rectangle of paper. Navigation, sticky headers, background gradients, and scroll-driven effects are gone. What remains is the content, and without a print stylesheet, that content often looks wrong: text runs edge to edge with no margin, links become meaningless blue words with no visible URL, images bleed off the page, and headings land at the bottom of a sheet with no body text following them. A print stylesheet is a targeted set of rules that makes the printed version of your page readable and professional. This reading assignment covers how to write one, from scoping print rules through typography, link handling, color, and page-break control.

Scoping Rules to Print

Print-specific CSS lives inside an @media print block. Rules inside it apply only when the page is printed or previewed in the browser's print dialog. Everything outside the block still applies to print as well (CSS cascades normally across media), so the print block is not a standalone stylesheet: it is a layer of overrides on top of your screen styles.


        @media print {
            /* These rules apply only when printing */
            body {
                font-size: 12pt;
            }
        }
    

You can also link a separate print stylesheet in your HTML with a media attribute on the <link> tag. The browser still downloads the file on screen (so it is cached when the visitor prints), but it only applies the rules during print. A separate file keeps print rules out of your main stylesheet, which is cleaner for large projects. For smaller sites, an @media print block at the end of your main file is simpler and avoids an extra request.


        <link rel="stylesheet" href="/css/print.css" media="print">
    

Hiding What Paper Does Not Need

Navigation menus, sticky headers, footers with social icons, buttons, form controls, and any interactive element have no function on paper. The first job of a print stylesheet is to remove them so they do not waste ink or space.


        @media print {
            nav,
            footer,
            .site-header,
            .no-print,
            button,
            aside {
                display: none;
            }
        }
    

A utility class like .no-print is useful for elements that do not belong to a single semantic category but should still disappear on paper, such as a decorative banner or an embedded video player. Add the class in your HTML and hide it once in the print block rather than targeting each element individually.

Typography on Paper

Screen typography and print typography solve different problems. A screen renders light on dark pixels at varying distances and resolutions; paper reflects ambient light at a fixed, close reading distance with far higher resolution. Several adjustments make text comfortable on paper.

Use Point Sizes

The pt unit was designed for print. One point equals 1/72 of an inch, and printers resolve it precisely. Body text between 10pt and 12pt is standard for printed documents. Using pt in your print block ensures sizes map predictably to the physical page rather than being reinterpreted from pixel or rem values.

Consider a Serif for Body Text

On paper, serif faces like Georgia or a system serif tend to read more comfortably than sans-serif faces at body sizes, because the serifs help the eye track along a line of printed text. This is not a hard rule, and your design may call for a sans on paper, but it is worth testing both in print preview. Set the font family inside your print block so it overrides the screen face without changing it.

Adjust Measure and Leading

A standard sheet of paper is wider relative to text size than most screen layouts, so without a max-width the text runs nearly edge to edge, making lines far too long to read comfortably. Set a print-specific max-width or generous margins on the body to keep the measure in a readable range. Line height can usually tighten slightly compared to screen, because paper's higher resolution makes tighter leading more legible than it would be on a pixel grid.


        @media print {
            body {
                font-family: Georgia, 'Times New Roman', serif;
                font-size: 12pt;
                line-height: 1.4;
                max-width: 45em;
                margin: 0 auto;
                color: #000;
            }
        }
    

Surfacing Links as URLs

A hyperlink on screen is interactive: the visitor clicks or taps it. On paper a link is just colored text with no way to follow it, which makes it useless unless the URL is visible. The standard technique uses the ::after pseudo-element and the attr() function to append the URL after the link text.


        @media print {
            a[href]::after {
                content: " (" attr(href) ")";
                font-size: 0.9em;
                color: #555;
            }
        }
    

This turns a link like <a href="https://example.com">Example</a> into "Example (https://example.com)" on the printed page. The selector a[href] targets only links that have an href attribute, so anchors used as targets or JavaScript hooks do not get a meaningless empty parenthetical.

For internal links or links with very long URLs, the appended text can clutter the page. You can scope the rule to only external links, or truncate the URL display. A common approach hides the URL for internal links that start with / or #:


        @media print {
            a[href^="/"]::after,
            a[href^="#"]::after {
                content: none;
            }
        }
    

Controlling Color on Paper with print-color-adjust

By default, most browsers strip background colors and images when printing to save ink. This is usually the right behavior, but there are cases where a background color carries meaning: a brand header, a status badge, or a data visualization where color encodes a value. The print-color-adjust property tells the browser whether it is allowed to optimize colors for the printer or whether it must preserve them exactly as specified.


        @media print {
            .brand-header {
                print-color-adjust: exact;
                -webkit-print-color-adjust: exact;
                background: #006eb6;
                color: #fff;
            }
        }
    

The value exact forces the browser to render the declared colors and backgrounds faithfully, regardless of its ink-saving preferences. The value economy (the default) lets the browser strip or alter them as it sees fit. Use exact sparingly and only where the color is genuinely meaningful, since forcing full-color backgrounds onto every printed page wastes ink and can make text harder to read if the contrast is tuned for screen rather than paper. The -webkit- prefix is still needed for Safari and older Chrome; include both declarations.

Page Break and Fragmentation Control

When content flows across multiple sheets, the browser decides where to break between pages. Without guidance, it can split a heading from its following paragraph, break a figure in half, or leave a single orphaned line at the top or bottom of a page. The fragmentation properties give you control over where breaks are allowed.

break-inside

The most commonly useful property. Setting break-inside: avoid on an element tells the browser not to split it across a page boundary. Use it on figures, blockquotes, code blocks, and card-like components that lose meaning when torn in two.


        @media print {
            figure,
            blockquote,
            pre,
            .card {
                break-inside: avoid;
            }
        }
    

break-before and break-after

These properties force or prevent a page break before or after an element. The value page forces a break, which is useful before a major section heading so each chapter starts on a fresh sheet. The value avoid prevents a break, which keeps a heading glued to the content that follows it.


        @media print {
            h2 {
                break-before: page;
                break-after: avoid;
            }
        }
    

Use forced page breaks with restraint. Every break-before: page starts a new sheet, and if your content has many headings, the result is pages with a heading and a few lines followed by a blank half-page. Reserve forced breaks for top-level sections, and let the browser handle sub-sections naturally.

Orphans and Widows

The orphans property sets the minimum number of lines that must remain at the bottom of a page before a break, and widows sets the minimum at the top of the next page. Increasing them from the browser default of two to three prevents the common problem of a single lonely line sitting at the top or bottom of a sheet.


        @media print {
            p {
                orphans: 3;
                widows: 3;
            }
        }
    

Seeing the Changes

The demo below applies print-style rules to a contained page section so you can see the effect without opening print preview. Toggle between the screen and print views to watch the navigation disappear, the link URL surface, and the typography shift to a serif with tighter leading.

Home About Projects Contact
Understanding Print Stylesheets
A well-crafted print stylesheet ensures your content reads as clearly on paper as it does on screen. The CSS media query specification provides the mechanism for scoping rules to print, and the CSS Fragmentation spec defines the page-break properties that keep content from splitting awkwardly across sheets. Together they give you full control over the printed page.

Testing with Print Preview

The demo above simulates the visual changes, but the only way to see your actual print stylesheet working is to open the browser's print preview. Each browser reaches it slightly differently:

  • Chrome and Edge: press Ctrl+P (Windows/Linux) or Cmd+P (macOS) to open the print dialog, which shows a live preview of the printed output on the left side
  • Firefox: press Ctrl+P or Cmd+P; Firefox renders a full-page preview before showing the dialog
  • Safari: press Cmd+P; the preview renders inside the print dialog and updates as you change settings

Test in at least two browsers, because each engine makes slightly different decisions about default margins, header/footer text, and how it handles fragmentation hints. If a break property seems to have no effect in one browser, check another before assuming your CSS is wrong. Print rendering is one of the areas where browser behavior still diverges more than on screen.

Putting It Together

A complete print stylesheet is usually shorter than you expect. Hide the interactive shell, switch to a print-appropriate typeface and size, surface link URLs, protect key elements from breaking across pages, and force color only where it carries meaning. Test in print preview, adjust margins and breaks until the output reads like a document rather than a screenshot, and your content is ready for paper.