In the world of modern web design, accessibility and aesthetics often seem like they’re at odds. Designers want slick interfaces without clunky outlines, while developers and accessibility advocates push for inclusive interaction models that support keyboard navigation and screen readers. One small but powerful CSS selector has quietly changed the game: :focus-visible css
.
This pseudo-class is a smarter, more selective way to apply focus styles—ensuring a more inclusive experience for keyboard users while maintaining a polished visual appearance for mouse users. If you’ve ever removed :focus
styles for aesthetic reasons, you’re not alone—but here’s why you shouldn’t, and how :focus-visible
can be your solution.
What is :focus-visible
?
The :focus-visible
pseudo-class is a CSS selector that applies styles only when an element should indicate focus—primarily when it’s focused via keyboard interaction. It doesn’t trigger on mouse clicks or touch interactions, which means your users don’t get unsightly focus outlines when they don’t need them.
Compare this to the classic :focus
selector, which applies styles whenever an element is focused, regardless of how it happened. This often results in visual clutter or awkward outlines on buttons and links that were clicked with a mouse—something many designers find disruptive and opt to remove.
Unfortunately, removing :focus
styles entirely can have disastrous consequences for keyboard users. Without clear focus indicators, people navigating via keyboard (using Tab, Shift+Tab, arrow keys, etc.) can get lost in your interface, making your site frustrating or even unusable.
The Problem with Removing :focus
Designers often override or remove focus styles because they interfere with the visual design of a site. Those default dotted or glowing outlines? Not exactly what you’d call brand-aligned.
But when you do this, you’re effectively excluding users who rely on keyboard navigation—users with motor disabilities, users using screen readers, and power users who prefer keyboard shortcuts for efficiency. These visitors depend on clear, visible indicators to understand where they are on a page.
Removing focus styles breaks accessibility. It’s the equivalent of hiding the mouse pointer from sighted users—it leaves people flying blind.
Why :focus-visible
is Better
Here’s where :focus-visible
comes in. It applies focus styles only when the browser determines the user needs them, typically during keyboard navigation.
Here’s a simple example:
This setup removes focus outlines for mouse users while preserving them for keyboard users—allowing you to maintain a clean design without sacrificing accessibility.
What’s especially great is that :focus-visible css
is supported in all major browsers as of 2021 (except for Internet Explorer, which is now obsolete). It behaves similarly to the JavaScript-based :focus-ring
polyfill that was used before native support caught up.
Styling Tips: Make It Stand Out, Not Stick Out
When using :focus-visible css
, it’s important to style it in a way that:
-
Contrasts clearly with the background – the focus indicator should be immediately visible.
-
Fits your brand – don’t rely on the browser default; customize it.
-
Is not subtle – this isn’t the place to be minimal. If it’s hard to see, it’s not helpful.
Here’s an enhanced version of the earlier example:
This creates a visually striking outline that’s both accessible and on-brand, assuming you tweak the colors to match your palette. The glow effect draws the eye without disrupting the design.
Make sure your chosen focus styles pass WCAG 2.1 contrast standards. Aim for a minimum contrast ratio of 3:1 against adjacent colors. You can use tools like the WebAIM contrast checker to confirm this.
Best Practices for Using :focus-visible css
-
Don’t remove focus indicators entirely – they’re essential for accessibility.
-
Use
:focus-visible
instead of:focus
when you want to tailor styles to keyboard navigation. -
Test with keyboard navigation – open your site and use Tab to move around. Is it obvious where the focus is?
-
Be consistent across components – form inputs, buttons, links, custom components—all should have clear, consistent focus styles.
-
Use transitions to make focus indicators feel intentional and polished, rather than jarring.
The Bottom Line
In 2025, there’s no excuse to build interfaces that exclude users. With :focus-visible css
, we now have a simple, elegant tool to balance visual design with accessibility. It’s time to stop choosing between form and function—focus-visible
gives us both.
So the next time you’re tempted to wipe out those ugly outlines, pause. Instead, style :focus-visible
thoughtfully. Your users—especially the ones who need it most—will thank you.
Need help with making your website more accessible? We provide full website accessibility audits for £150, a fee that is reduced from the bill if you choose to work with us. Check out the service here