CSS Focus Visible Accessibility
Style accessible focus indicators using CSS focus-visible to show outlines only for keyboard navigation not mouse.
Code
button:focus-visible {
outline: 3px solid #4f46e5;
outline-offset: 2px;
}
button:focus:not(:focus-visible) {
outline: none;
}CSS Focus Visible Accessibility
Style accessible focus indicators using CSS focus-visible to show outlines only for keyboard navigation not mouse.
Code
button:focus-visible {
outline: 3px solid #4f46e5;
outline-offset: 2px;
}
button:focus:not(:focus-visible) {
outline: none;
}
Explanation
:focus-visible draws the outline only when the browser judges that the interaction came from the keyboard rather than the mouse. Expected behavior: keyboard users keep a visible focus ring while mouse clicks do not show it. Caveat: never remove the outline without supplying a replacement, or keyboard navigation becomes inaccessible.
Interactive Tools for This Topic
WCAG Color Contrast CheckerCalculate WCAG 2.1 color contrast ratios between foreground and background colors. Verify AA and AAA compliance levels for normal and large text accessibility.Tailwind Color Palette GeneratorGenerate a balanced 50-950 Tailwind CSS custom property color scale from any hex, RGB, or HSL base color with WCAG 2.1 contrast ratios for every stop.CSS Color Name LookupTranslate between CSS keyword color names and hex values with RGB and HSL conversions, exact name matching, and nearest-color suggestions.CSS Color ConverterConvert colors between HEX, rgb(), and hsl() instantly, with support for shorthand hex and rgb or hsl inputs. Fully offline and dependency free.
Report a problem with this exampleOpens a pre-filled issue on GitHub.