Full answer
Forced colors mode is an operating system feature, such as Windows contrast themes. When it is on, the browser replaces many of your colours with a small set chosen by the user, so that text is easy to read. The CSS media feature is forced-colors: active.
The browser changes properties such as color, background-color, border-color and outline-color, and removes box-shadow and background images in many cases. Text shadows are removed too. SVG fills and strokes are not changed unless they use currentColor or a system colour.
This causes bugs in custom UI:
- A custom checkbox or switch drawn only with background colour can become invisible, because the background is replaced.
- Information shown only by a background colour or shadow disappears. A focus ring made with
box-shadowis not shown, but a realoutlineis kept. - Icons in SVG with a fixed fill can vanish on a forced dark background.
Fixes:
- Use real borders and outlines for states, not only background or shadow.
- Use
currentColorin SVG so icons follow the text colour. - Use system colour keywords such as
ButtonText,Canvas,CanvasText,HighlightandLinkTextinside@media (forced-colors: active)where a manual rule is needed. - If you must keep your own colour for a part, set
forced-color-adjust: noneon that element, with care, and use system colours inside it. Do not set it on the whole page. - Use transparent borders, such as
border: 2px solid transparent, so there is something for forced mode to colour.
Test by turning on a contrast theme in the operating system, or with DevTools emulation of forced-colors.
In normal mode the chip is blue with white text and a blue shadow ring on focus. In forced colors mode, the shadow is removed, but the transparent outline becomes visible in a system colour, and the chip uses the system highlight colours, so it is still clear.
Note that outline: 3px solid transparent is a known technique, because transparent outlines become visible only in forced colors mode.
<style>
.chip { display: inline-block; padding: 4px 12px; border-radius: 12px; background: #e6f0ff; border: 2px solid transparent; }
.chip[aria-pressed="true"] { background: #0a6cff; color: #fff; }
button.chip:focus-visible { box-shadow: 0 0 0 3px #0a6cff; outline: 3px solid transparent; }
@media (forced-colors: active) {
.chip[aria-pressed="true"] { border-color: Highlight; background: Highlight; color: HighlightText; }
}
</style>
<button type="button" class="chip" id="chip" aria-pressed="true">Selected</button>Checked with forced colors emulated in Chrome, not with a real operating system contrast theme. Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- Forced colors mode is controlled by the user's operating system.
- It changes colours and removes box-shadow in many cases.
- Use borders and outlines for states and focus.
- Use currentColor in SVG and system colours in a forced-colors media query.
- Test with a contrast theme or DevTools emulation.
Common mistakes
- Using box-shadow as the only focus indicator, which disappears in forced colors mode.
- Setting forced-color-adjust: none on the whole page.
- Drawing icons with a fixed fill, so they disappear on the forced background.
Follow-ups
- Which CSS media feature detects forced colors mode?
- When is forced-color-adjust: none acceptable?
Tips
- Explain what the OS does: it replaces colours and removes shadows.
- Name the transparent outline technique and currentColor for SVG.