CSS forced-color-adjust Property Explained
The CSS forced-color-adjust property allows developers
to opt specific elements out of user-agent color overrides in
high-contrast accessibility modes, such as Windows Contrast Themes
(formerly Windows High Contrast Mode). When forced colors mode is
active, the operating system enforces a restricted, user-selected color
palette across web pages to ensure readability. This article explains
how the forced-color-adjust property works, why developers
use it to disable accessibility color overrides, and how to implement it
responsibly.
What is Forced Colors Mode?
Operating systems provide accessibility features designed for users
with low vision, light sensitivity, or visual impairments. One such
feature is Forced Colors Mode. When enabled, the browser overrides
author-defined styling—specifically properties such as
color, background-color,
border-color, text-decoration-color, and
outline-color—replacing them with system-defined colors
that guarantee high contrast.
While this drastically improves legibility for plain text and standard layouts, it can inadvertently break interface elements whose function strictly depends on specific colors.
Syntax and Values
The forced-color-adjust property accepts two standard
values:
auto: The default behavior. The element's colors are automatically adjusted to match the active forced colors palette.none: Disables the forced color overrides for the element and its descendants, preserving the author's custom styling.
.custom-swatch {
forced-color-adjust: none;
}An older value, preserve-parent-color, exists in some
legacy implementations to retain the computed color of the parent, but
auto and none are the standard
specifications.
Why Disable Forced Color Overrides?
The primary reason to use forced-color-adjust: none is
to protect visual indicators where color is the core mechanism of
comprehension. In forced colors mode, distinct background colors are
flattened into a single system background color, which strips critical
context from certain components:
- Color Pickers and Swatches: If a digital paint app or e-commerce store displays a series of color swatches (e.g., choosing a t-shirt color), forced colors mode replaces every swatch with the same system background, making all options look identical.
- Data Visualizations: In pie charts, heatmaps, or multi-line graphs, distinct hues are required to differentiate data sets. Stripping these hues makes the visualization unreadable.
- Status Badges: A set of tags indicating "Success", "Warning", and "Critical" often rely on specific colors. If borders or icons do not accompany the text, users may miss contextual cues when colors are flattened.
- CSS-Rendered Graphics: Complex UI icons or artistic graphics built entirely out of CSS shapes and colors become invisible or distorted if their background and border colors are overridden by the browser.
Practical Implementation
To protect an element, you can apply the property directly to the
relevant selector or scope it within the
@media (forced-colors: active) media query:
@media (forced-colors: active) {
.palette-swatch {
forced-color-adjust: none;
}
}Using the media query ensures that the declaration is only evaluated and applied when the user's environment explicitly enforces high-contrast overrides.
Best Practices and Caveats
Disabling accessibility overrides should be done with extreme caution. High-contrast modes exist to allow users with visual impairments to navigate the web comfortably.
- Do Not Apply Globally: Never apply
forced-color-adjust: noneto thebodytag, broad layout containers, or entire web pages. Doing so completely undermines the user's explicit accessibility preferences. - Provide Secondary Cues: Relying on
forced-color-adjust: noneshould not be a replacement for good accessibility design. Always accompany color with text labels, patterns, or icons so that users who cannot distinguish colors can still understand the content. - Maintain Contrast Manually: If you opt an element out of forced colors mode, you must ensure that its author-defined colors still meet high contrast ratios (such as WCAG AAA) against the surrounding interface.