CSS Reference ยท Colors and Backgrounds
The forced-color-adjust property
Reference for the CSS forced-color-adjust property: when to opt an element out of forced colors mode, why it is risky, and how to keep text readable.
Some users switch on forced colors mode (for example Windows contrast themes) to get a small, high-contrast palette on every site. The browser then overrides many of your colors with system colors. The forced-color-adjust property lets an element say whether the browser may do that.
By default (auto) the override happens, and that is almost always what you want. Use none only for content whose colors carry meaning that would be lost, such as a color swatch in a picker, and then make sure the result stays readable.
.swatch { forced-color-adjust: none; }
Try it
You will only see a difference if forced colors mode is active on your device. The status line uses the forced-colors media feature to tell you.
Syntax
forced-color-adjust: auto | none | preserve-parent-color
- Initial value:
auto - Applies to: all elements and text
- Inherited: yes
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
auto |
The browser may replace colors with the forced palette. This is the default and the recommended choice. |
none |
The element keeps the colors you specified. Properties that forced colors would normally override are left alone. |
preserve-parent-color |
Like none for the element's text, but color is kept equal to the parent's forced color so text stays consistent with its surroundings. Useful for an element, such as an SVG icon, that uses currentcolor. |
Usage notes
- Treat
noneas a last resort. Forced colors exist for people with low vision, light sensitivity or other needs. Overriding them can make your content unreadable for exactly those people. - If you opt out, take responsibility for contrast. Pair the element with system colors (
Canvas,CanvasText,LinkText,ButtonText) for borders and text, as the swatches do, so the surrounding text still passes. - Good candidates: color pickers, charts and legends where color is the data, and images drawn with CSS backgrounds that must keep their look.
- Bad candidates: whole pages, navigation, buttons and body text.
- It inherits, so setting it on a container affects everything inside. Scope it tightly to the specific element.
- Test it. Turn on a contrast theme in your operating system or use your browser's developer tools to emulate forced colors.
- Prefer
forced-colorsqueries for adjustments. Inside@media (forced-colors: active)you can add a visible border to a control that relied on a background color alone.
Browser support
Supported in Chromium-based browsers, Firefox and Safari in current versions; check a compatibility table for the exact releases and for preserve-parent-color, which is less widely implemented.
Related
forced-colorsโ detects forced colors mode- System colors โ colors safe to use in forced mode
color-schemeโ declares light and dark support- Lesson: Accessibility in CSS