:focus-visible
Widely availableSince 202296% of users
Styles focus indicator only when keyboard navigation is used. Hides focus ring for mouse users.
What's modern
From web-features, MDN's browser data and our snippets, checked dailyModernIn every major browser since March 2022. Widely available since September 2024.
The old way and the modern waySee the snippet: Focus styles without annoying mouse users →
Old way 4 lines
button:focus {
outline: 2px solid blue;
}
/* Outline appears on mouse click. Often removed with outline: none. */Modern 3 lines
button:focus-visible {
outline: 2px solid var(--focus-color);
}See how modern your own CSS is.Check your CSS →
Quick example
button:focus-visible { outline: 3px solid #4A90E2; outline-offset: 2px; }Examples
Show focus ring only for keyboard navigation
button:focus-visible {
outline: 2px solid blue;
outline-offset: 2px;
}
/* Shows outline for Tab key, hides for mouse click */Keyboard users see a visible focus indicator; mouse users only see it while tabbing through.
Style interactive elements for accessibility
input:focus-visible,
button:focus-visible,
[role="button"]:focus-visible {
box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}Apply consistent focus styles to all interactive elements when navigated via keyboard.
Remove default browser outline, add custom
button {
outline: none; /* Remove default */
}
button:focus-visible {
outline: 2px solid currentColor;
}Replace the default gray outline with a styled indicator that matches your design.
Common pitfalls
- Different from :focus:focus matches all focus, including mouse clicks. :focus-visible only matches keyboard focus. Don't confuse them.
- Mouse users see no visible focusWith :focus-visible alone, mouse users clicking a button won't see a focus indicator. That's intentional: mouse users can see what they're clicking. But consider adding :focus styling too if you want all users to see focus.
- Browser decides when :focus-visible appliesThe browser decides whether to match :focus-visible based on how the user navigated (keyboard vs mouse). You can't override this. That's on purpose: it follows how the person is using the page.
:focus-visible browser support
BaselineWidely availableThis feature is well established and works across many devices and browser versions. It has been available across browsers since 2022.Safe to use without fallbacks.
Usage96%of people can use this4% use a browser without it.
Browsers
86+
85+
15.4+
86+Mobile
86+Android
85+Android
15.4+iOS