In short
A good focus state is clearly visible on every interactive element, has at least 3:1 contrast against its surroundings, and isn't hidden by other content. Use :focus-visible with a solid outline and an offset of about 2px, and never remove outlines without a replacement. A two-colour outline works on any background. Test by tabbing through your site.
Why they matter
When someone uses a keyboard, the focus indicator acts as their mouse cursor. Take it away, and they're navigating blind. People who rely on it include those with motor impairments, screen magnifier users, and many others. See keyboard navigation done properly.
Removing it is one of the most widespread accessibility mistakes on the web.
What the rules say
- WCAG 2.4.7 Focus Visible (Level AA): there has to be a visible focus indicator.
- WCAG 1.4.11 Non-text Contrast (Level AA): visual information needed to identify states has to have at least 3:1 contrast against adjacent colours.
- WCAG 2.4.11 Focus Not Obscured (Minimum) (Level AA): focused items can't be entirely hidden by things such as sticky headers.
- WCAG 2.4.13 Focus Appearance (Level AAA): sets a stronger standard for size and contrast. It's a useful target, even though few sites have to meet AAA.
A robust default
:focus-visible {
outline: 3px solid #1a56db;
outline-offset: 2px;
}
Why this works:
:focus-visibleshows the ring when the browser judges that it's helpful, typically for keyboard use, and usually not on a mouse click.outlinedoesn't affect layout, unlikeborder, so nothing shifts. See how to avoid layout shift.outline-offsetseparates the ring from the element, which makes it clearer.- 3px is easy to see.
- Outline follows
border-radiusin current browsers, so it should look neat on rounded buttons.
Set it once, globally, and only override it where you've got good reason to. Put it in your design tokens:
:root {
--focus-color: #1a56db;
--focus-width: 3px;
--focus-offset: 2px;
}
:focus-visible {
outline: var(--focus-width) solid var(--focus-color);
outline-offset: var(--focus-offset);
}
Don't do this
/* The classic mistake */
:focus { outline: none; }
button:focus { outline: 0; }
These often come from an old CSS reset or a designer's dislike of the outline after clicking. Search your code for outline: none, outline: 0 and any framework's equivalent. Every instance needs a replacement.
Working on any background
A blue ring disappears on a blue button, or on a dark photograph. The answer is a two-colour indicator.
:focus-visible {
outline: 3px solid #ffffff;
outline-offset: 2px;
box-shadow: 0 0 0 6px #111111;
}
The white and dark bands mean that at least one of them contrasts with whatever's behind it. This is especially useful on sites with hero images or mixed sections. Alternatively, set the focus colour within each themed section:
.section-dark {
--focus-color: #ffd166;
}
Note that some high contrast modes remove box shadows, so keep the outline as your main indicator. Windows High Contrast respects outlines. That's another reason not to rely on a shadow alone. If you do want shadow-only rings, add outline: 2px solid transparent, which appears in forced-colours mode.
Common failures
Cut off by overflow. overflow: hidden on a parent can clip the ring. Use a negative outline-offset, or adjust the container:
.card-link:focus-visible {
outline-offset: -3px;
}
Hidden under sticky headers. A focused item scrolls under a fixed header:
html {
scroll-padding-top: 5rem;
}
Colour change only. A subtle colour shift isn't enough, and it fails for many users. Change shape or add an outline as well. See how to design for colour blindness.
Focus on a hidden input. Custom checkboxes often hide the real input, so the visible part has no ring. Use a sibling selector:
input[type="checkbox"]:focus-visible + .fake-checkbox {
outline: 3px solid var(--focus-color);
outline-offset: 2px;
}
Whole-card links. Show the ring on the entire card, not on an invisible overlay. :focus-within can help.
Same as hover. Make focus at least as strong. Ideally, it should be different enough to be clear when both occur.
Focus on non-interactive elements. Headings that receive focus through a script, with tabindex="-1", don't always need a heavy ring, but check that users can still follow what's happening.
Inputs
Form fields should have an obvious focus state, too. Browsers treat text inputs as always showing :focus-visible, even with a mouse, which is helpful, since it shows where you're typing. A thicker border plus an outline works well. See how to build an accessible form.
Making it look good
Focus rings don't have to be ugly. Designers can:
- Use your brand's accent colour, if the contrast works
- Match the radius with the element
- Keep the offset consistent
- Animate gently, but only if it doesn't delay visibility, and respect
prefers-reduced-motion
Then include focus states in your design files, alongside hover and pressed states, so they're seen as part of the design instead of an afterthought. See how to create accessible colour contrast.
Tailwind and component libraries
In Tailwind, use the focus-visible: variant:
<a class="focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-teal-700" href="/pricing">Pricing</a>
Watch out for outline-none, which AI tools and templates regularly add. Replace ad hoc classes with one shared style in your component library. See Tailwind or plain CSS?
How to test
- Tab through the whole page. Can you always see where you are?
- Check different backgrounds: hero, footer, cards and modals.
- Check contrast of the ring against nearby colours, using a contrast tool. It should be 3:1 or above.
- Check zoomed in, at 200%.
- Check dark mode and forced colours mode. Chrome's DevTools can emulate this.
- Test with sticky headers, by tabbing back upwards.
- Search your code for outline removal.
Automated tools can't reliably judge whether a focus indicator is visible enough, so a human check is needed. See how to test accessibility without a specialist and how to make a website accessible.
If you'd like a review of your site's accessibility, book a call.
Common questions
What is a focus state?
It's the visual indicator showing which element will respond to the keyboard, such as a ring around a button. Keyboard users rely on it to see where they are on a page, in the same way that mouse users rely on a cursor.
What is the difference between focus and focus-visible?
The :focus selector applies whenever an element has focus, including after a mouse click. The :focus-visible selector applies when the browser decides that a visible indicator is useful, typically during keyboard use. It's usually the better choice for your focus styles.
Can I remove the outline on buttons?
Only if you replace it with an equally clear focus style. Removing it altogether makes your site very hard to use by keyboard and fails accessibility requirements. Use :focus-visible, if you don't want a ring after mouse clicks.
How much contrast does a focus indicator need?
WCAG requires non-text indicators to have at least 3:1 contrast against adjacent colours. Check it on every background you use. A two-colour indicator, such as a white and a dark band, helps it remain visible on any surface.