CSS forced-colors media query for Windows High Contrast
Windows High Contrast support without broken UI
Windows High Contrast and similar forced-color modes ignore most of your CSS. Custom backgrounds are replaced, drop shadows disappear and border colours are swapped for system colours. forced-colors lets you opt back in with system colors that the OS guarantees will be readable.
The old hack vs the modern fix
View demo/* no border: in forced colors the background is replaced
and the button edge vanishes. Just text is left. */
.btn {
background: var(--accent);
color: white;
border: none;
}.btn {
background: var(--accent);
color: white;
border: 1px solid transparent;
}
@media (forced-colors: active) {
.btn {
background: ButtonFace;
color: ButtonText;
border: 1px solid ButtonText;
}
}
/* High Contrast users see a real button instead of a coloured rectangle */<button class="bg-indigo-500 text-white border border-transparent forced-colors:bg-[ButtonFace] forced-colors:text-[ButtonText] forced-colors:border-[ButtonText]">Subscribe</button>Forced colors browser support
Live demo
Why the modern way wins
Buttons stay buttons
In forced-colors mode the OS strips backgrounds and shadows. Without an opt-in, the button you styled with a coloured background and no border becomes invisible. ButtonFace and ButtonText guarantee the OS will render them with a readable contrast pair.
Pairs with prefers-contrast
Use @media (prefers-contrast: more) for users who asked for higher contrast but are not in forced-colors mode. The two queries cover different audiences. Stack them when both matter.
Opt out of overrides
forced-color-adjust: none tells the browser "trust me, I have already adapted these colours". Use it sparingly and only after you have confirmed the contrast still works.
- Key Change
- OS-driven palette
- System colors guarantee contrast
- Old Approach
- no fallback
- Buttons disappear in High Contrast
- Modern Approach
- @media (forced-colors: active)
- Opt in with system colors
How it works
Windows High Contrast (now called Contrast Themes) and similar modes on other platforms force a small palette of OS-defined colours onto every page. The browser replaces background colours, removes drop shadows and paints borders in a system colour. If your button relied on a coloured background and had no border, it ends up as plain text with no edge. A 1px solid transparent border helps here, because forced colors paint it in a visible colour.
The fix is one query. @media (forced-colors: active) fires only when the OS is in a forced-colors mode. Inside it, set the colours that matter using system color keywords like ButtonFace, ButtonText, LinkText, Highlight, and HighlightText. These map to whatever palette the user picked, so you do not need to know in advance which colours they want.
forced-color-adjust: none opts a specific element out of the OS overrides. Reach for it only when you have already paired the foreground and background using system colours, otherwise you are taking responsibility for accessibility the browser was handling for you.