Color scheme

Print and Forced Colors

You spend hours choosing colors, building token systems, and testing contrast ratios. Then a user prints your page and the browser strips out every background color to save ink. Or a user on Windows enables High Contrast Mode and the operating system replaces your entire palette with its own. Both of these situations are the browser overriding your color decisions for a good reason, but sometimes the override breaks things that the user actually needs to see. CSS gives you two tools to manage these situations: print-color-adjust for print output and the forced-colors media query with forced-color-adjust for high contrast environments.

Print and print-color-adjust

When a user prints a web page, the browser applies its own judgment about which colors to keep and which to discard. By default, most browsers strip background colors and background images to save ink. This behavior is controlled by the print-color-adjust property, which has two values:

  • economy (the default): The browser is free to modify or remove colors and images to optimize for the output device. On a printer, this typically means dropping backgrounds and adjusting text to ensure legibility on white paper.
  • exact: You are telling the browser that the colors on this element are intentional and meaningful, and it should preserve them as closely as possible. The browser will try to reproduce your backgrounds, gradients, and images exactly as declared.

The important word here is "try." The exact value is a hint, not a command. The browser and the output device still have the final say. But for elements where color carries meaning, like a status badge, a chart, a color swatch, or a zebra-striped table, print-color-adjust: exact is the right signal to send.


        /* Preserve meaningful backgrounds when printing */
        @media print {
            .status-badge {
                print-color-adjust: exact;
            }

            .data-chart {
                print-color-adjust: exact;
            }

            .color-swatch {
                print-color-adjust: exact;
            }
        }
    
Legacy Prefix

Older versions of Chrome and Safari used -webkit-print-color-adjust instead of the standard property name. The unprefixed version is now supported across all major browsers, but you may still see the prefixed form in older codebases. The earlier name color-adjust has been deprecated entirely.

When to Use exact

The default economy behavior is almost always correct for body text, navigation, headers, and general layout. You should only reach for exact when an element's color is part of its content, not just its decoration. A few common examples:

  • A table with alternating row colors where the striping helps the reader track across columns
  • A chart or graph where the bar or line colors represent different data series
  • A product page where a color swatch needs to show the actual available colors
  • A code block where syntax highlighting uses background colors to distinguish language elements

If the color is purely aesthetic (a decorative gradient, a brand-colored header bar), leave it at economy and let the printer do its job. Users printing your page probably want legible text on white paper, not a faithful reproduction of your dark theme.

Forced Colors Mode

Forced colors mode is an accessibility feature where the operating system overrides the colors on a web page with a user-chosen high contrast palette. The most well-known implementation is Windows High Contrast Mode, but the feature is defined as a platform-independent standard. When forced colors mode is active, the browser replaces your custom colors with system colors drawn from the user's preferences. Backgrounds typically become solid black or white, text becomes a high contrast color, and links and buttons use distinct system colors for visibility.

The browser does not just swap out your CSS variables. It overrides entire categories of properties: color, background-color, border-color, outline-color, column-rule-color, text-decoration-color, box-shadow (forced to none), and text-shadow (forced to none). Properties that are not color-related, like border-width, padding, and font-size, are left alone.

Detecting Forced Colors

The forced-colors media query lets you write styles that apply only when the user has forced colors enabled:


        @media (forced-colors: active) {
            /* Styles for high contrast mode */
        }

        @media (forced-colors: none) {
            /* Normal mode (this is the default) */
        }
    

Inside this query, you can use CSS system color keywords to reference the user's chosen palette. These keywords resolve to whatever colors the user has configured:


        @media (forced-colors: active) {
            .card {
                border: 2px solid ButtonText;
            }

            .link-icon {
                fill: LinkText;
            }
        }
    

Common system color keywords include Canvas (background), CanvasText (text on the background), LinkText (hyperlinks), ButtonFace (button backgrounds), ButtonText (text on buttons), Highlight (selected item background), and HighlightText (text on a selected item). The browser maps these to the user's actual preferences, so you never hardcode a specific high contrast color. You just reference the role.

Replacing the Legacy Query

Older codebases may use @media (-ms-high-contrast: active), which was a Microsoft-specific media feature for Windows High Contrast Mode. The standardized @media (forced-colors: active) replaces it entirely. If you encounter the old syntax, update it.

Fixing Broken Components

Most of the time, the browser's automatic color replacement works well. Text becomes legible, buttons become visible, and links stand out. But some components rely on color in ways that the forced colors algorithm does not understand. When the browser strips your colors and replaces them with system defaults, the visual meaning can be lost. Here are the most common breakage patterns and how to fix them.

Borders That Disappear

A component that uses only box-shadow for its visual boundary will lose that boundary entirely in forced colors mode because shadows are forced to none. The fix is to add a transparent border that the browser can replace with a visible system color:


        .card {
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
            border: 1px solid transparent;
        }

        /* In forced colors mode, the transparent border becomes visible
           because the browser replaces it with a system color */
    

This is a widely recommended defensive pattern. The transparent border costs nothing visually in normal mode, but gives the browser something to work with in forced colors mode.

Icons That Vanish

SVG icons that use hardcoded fill colors may become invisible if the icon color matches the forced background. The fix depends on the icon type. For single-color icons, set the fill to currentColor so it inherits from the text color, which the browser will replace appropriately:


        <svg aria-hidden="true" viewBox="0 0 24 24">
            <path fill="currentColor" d="M12 2L2 7l10 5 10-5z" />
        </svg>
    

For multi-color icons or illustrations where the original colors are meaningful (like a logo or a chart legend), you can opt the element out of forced color adjustment:


        @media (forced-colors: active) {
            .brand-logo {
                forced-color-adjust: none;
            }
        }
    

Custom Controls That Lose State

Toggle switches, progress bars, and custom checkboxes often communicate state through background color alone. When forced colors mode replaces those backgrounds, a checked toggle can look identical to an unchecked one. The fix is to add a visual indicator that does not depend on color, such as a border change, a position shift, or an outline:


        @media (forced-colors: active) {
            .toggle[aria-checked="true"] .thumb {
                border: 2px solid Highlight;
            }

            .toggle[aria-checked="false"] .thumb {
                border: 2px solid ButtonText;
            }
        }
    

The forced-color-adjust Property

The forced-color-adjust property controls whether an element participates in forced colors mode. It has three values:

  • auto (the default): The browser will override the element's colors in forced colors mode.
  • none: The element is opted out of forced color replacement. Your original CSS colors will be preserved. The browser will also disable its text backplate (a contrast-ensuring background drawn behind text).
  • preserve-parent-color: The element preserves its parent's color value through inheritance, which is primarily useful for SVGs where child elements need to match the parent's forced text color.

Use forced-color-adjust: none sparingly and only inside a @media (forced-colors: active) block. The purpose of forced colors mode is to help users who need high contrast to read content. Opting out of it should be reserved for elements where the original color is genuinely part of the content, like color swatches, data visualizations, or brand marks. Never use it to override the user's preferences for aesthetic reasons.


        /* Only opt out where color IS the content */
        @media (forced-colors: active) {
            .color-swatch {
                forced-color-adjust: none;
            }

            .chart-legend .swatch {
                forced-color-adjust: none;
            }
        }
    

Testing in DevTools

You do not need a Windows machine to test forced colors mode. Both Chrome and Firefox DevTools let you emulate it directly.

In Chrome, open DevTools, press Ctrl+Shift+P (or Cmd+Shift+P on macOS) to open the command menu, and type "Emulate CSS media feature forced-colors." Select the active option. Your page will immediately render as if the user had enabled Windows High Contrast Mode. You can switch between active and none to toggle back and forth.

In Firefox, open DevTools, go to the Inspector tab, and look for the accessibility simulation options in the toolbar. You can emulate forced colors mode from there.

For print styles, Chrome DevTools also lets you emulate print media. Open the command menu and type "Emulate CSS media type print." This switches the rendering to print mode so you can see which backgrounds get stripped and verify that your print-color-adjust: exact declarations are targeting the right elements.

Testing in an emulator is a good start, but it does not replace testing on an actual Windows machine with High Contrast Mode enabled. The emulator approximates the behavior, but real system-level forced colors can interact with the OS theme in ways the emulator does not fully replicate.

Resources

Teaching Video Checklist

When you record your teaching video, make sure your teammates come away understanding these concepts:

  • What print-color-adjust does and the difference between economy (the default, which strips backgrounds) and exact (which preserves them)
  • When to use exact and when to leave the default alone (color as content vs. color as decoration)
  • What forced colors mode is, who uses it, and why the browser overrides your colors
  • How to detect forced colors mode with @media (forced-colors: active) and how to use system color keywords like Canvas, CanvasText, and ButtonText
  • The common breakage patterns: shadow-only borders vanishing, icons disappearing, and custom controls losing state
  • How to use forced-color-adjust: none responsibly, and why overusing it defeats the purpose of the accessibility feature

Show a live demo in your video. Pick a real component (a card, a toggle, or a set of buttons), show it breaking in forced colors mode using the DevTools emulator, and then fix it. Walk through both the broken and fixed versions so your teammates can see exactly what changes and why.