Focus Styles & Keyboard Navigation
The old problem: focus rings on every click
outline: none in the first place is understandable: the default focus ring used to appear on every interaction, including a plain mouse click, which many designers found visually noisy. The right fix for that problem was never to delete focus styling altogether — it was to show it selectively.:focus-visible — the actual fix
The :focus-visible pseudo-class (see :focus-visible & :focus-within for the full details) lets the browser decide when a focus indicator is actually useful — generally for keyboard and other non-pointer interaction — and applies your style only then. A mouse click that focuses a button doesn't trigger :focus-visible, but pressing Tab to reach that same button does.
/* Remove the outline only where you're replacing it with something
deliberately designed — never remove it with nothing in its place */
button {
outline: none;
}
/* Restore a clear, custom ring specifically for keyboard interaction */
button:focus-visible {
outline: 3px solid #2a6df4;
outline-offset: 2px;
}
/* Mouse clicks stay visually clean — no ring on a plain :focus that
isn't also :focus-visible */Designing a focus style that's actually visible
A focus ring that technically exists but is too thin, too low-contrast, or the wrong color against its background fails the same users a missing ring does. Treat the focus indicator itself as something that needs to pass the same bar as any other important content — see Color Contrast & Readability for the numeric thresholds. A generally safe baseline: at least a 2px outline, offset slightly from the element so it doesn't get swallowed by the element's own border, in a color with strong contrast against both the element and its surrounding background.
:focus-visible {
outline: 3px solid #2a6df4;
outline-offset: 2px;
border-radius: 4px; /* optional, to match rounded elements */
}
/* On a dark background, the same blue may not have enough contrast —
adjust per-context rather than assuming one color works everywhere */
.dark-panel :focus-visible {
outline-color: #8ab4ff;
}