CSS Reference ยท Media Queries and Features
The forced-colors media feature
Reference for the CSS forced-colors media feature: detect Windows High Contrast and similar modes, use system colors and forced-color-adjust, with examples.
The forced-colors media feature is true when the user's browser or operating system forces a limited palette on the page, such as Windows contrast themes. In that mode the browser overrides many of your colors (text, backgrounds, borders, links) with a small set of system colors chosen by the user, so that everything stays readable.
You do not fight this mode. You use the query to fix the places where your design relied on something that forced colors removes, like a background color that was the only visible edge of a button.
@media (forced-colors: active) { .badge { border: 1px solid CanvasText; } }
Try it
In forced-colors mode the browser replaces the page colors, and the label reports it. In normal mode the page looks as styled.
Syntax
@media (forced-colors: none) { /* ... */ } @media (forced-colors: active) { /* ... */ }
It is a discrete media feature.
Values
| Value | Description |
|---|---|
none |
Forced colors mode is not active. |
active |
The browser is forcing a limited color palette. |
Usage notes
- What gets overridden. Properties such as
color,background-color,border-color,outline-color,fillandstrokeare replaced. Background images and shadows are typically dropped or simplified. - Use system colors. Keywords like
Canvas,CanvasText,LinkText,ButtonFace,ButtonText,HighlightandGrayTextalways map to the user's chosen palette. Use them inside the query when you need to add something back. - Add real borders. An element distinguished only by a background color can disappear. Give buttons, cards and inputs a border (it can be transparent in normal mode; transparent borders become visible in forced colors).
- Do not turn it off lightly. The
forced-color-adjust: noneproperty opts an element out of the override. Use it only for content where color carries meaning, such as a color picker swatch, and keep the contrast accessible. - Icons. Inline SVG icons should use
currentColorso they follow the forced text color. Icons set as background images may vanish. - Related but different.
prefers-contrastleaves your palette in place; forced colors replaces it.
Browser support
Supported in current versions of the major browsers; the exact system integration (for example Windows contrast themes) varies, so check a compatibility table.
Related
prefers-contrastโ contrast preferenceprefers-color-schemeโ light or dark@mediaโ the at-rule- Lessons: Media Queries, Dark Mode