Windows contrast themes replace the colors on a page with a small system palette, and they drop box-shadow completely. If your focus ring is a shadow, keyboard users in that mode see nothing.
button:focus-visible {
box-shadow: 0 0 0 3px #0b6bcb;
outline: 2px solid transparent;
}
@media (forced-colors: active) {
.icon-button svg { fill: ButtonText; }
}
The transparent outline is invisible in normal mode, so the shadow is all you see. In forced colors mode the browser gives the outline a real system color, and suddenly there is a visible ring. One line, no media query needed.
The media query is for everything else. forced-colors: active matches when such a theme is on. Inside it, use system color keywords like CanvasText, ButtonText and Highlight so your custom parts follow the user’s palette. Inline SVG icons with a hard coded fill are a typical thing that vanishes otherwise.
Chrome 89, Firefox 89 and Safari 16 support the media feature. In Chrome DevTools I can emulate it from the Rendering panel. The caveat: do not try to undo the user’s colors with forced-color-adjust: none unless a part really breaks, because those colors are the reason the mode exists.
Further reading: MDN: forced-colors, MDN: system colors