Accessible Focus Styles: Keeping Keyboard Users Oriented
When you move around a page with the Tab key, something needs to show where you are. That marker is the focus indicator. Without it, keyboard users, including people who cannot use a mouse and many power users, are navigating blind.
Who relies on focus
- People who use only a keyboard because of motor or vision conditions
- Switch device and voice control users, whose tools often move focus
- Screen magnifier users following a point on screen
- Anyone whose mouse breaks, or who simply prefers the keyboard
The common mistake
Many sites remove the browser's default focus outline with outline: none because designers find it ugly. Unless you replace it with something equally visible, this makes the page nearly unusable by keyboard. It is one of the most common accessibility failures. See keyboard navigation and focus.
What WCAG asks for
- Focus Visible (2.4.7, level AA): any keyboard-operable interface must have a visible focus indicator
- Non-text Contrast (1.4.11, level AA): parts of the interface needed to identify controls, including focus indicators, should have at least a 3:1 contrast ratio against adjacent colors
- Focus Not Obscured (2.4.11, level AA in WCAG 2.2): the focused item should not be entirely hidden by things like sticky headers or cookie banners
- Focus Appearance (2.4.13, level AAA in WCAG 2.2): sets stricter size and contrast rules for the indicator, and is a useful target
Designing a good focus style
- Make it thick enough to see. Two pixels or more is a common starting point.
- Use strong contrast against both the element and the background around it. A two-tone ring (a dark line with a light line around it) works on any background.
- Offset it a few pixels from the element so it does not blend with the border.
- Keep the shape friendly. Match rounded corners where it looks tidy, but never make the ring so subtle that it disappears.
- Style all focusable elements: links, buttons, form fields, custom controls, and menu items.
Use focus-visible
The :focus-visible selector shows the ring for keyboard focus but typically not on mouse clicks, which solves the "ugly ring on click" complaint for many designers. Make sure that your fallback keeps focus visible in browsers where it does not apply.
Watch for sticky elements
If a fixed header covers a focused link as the page scrolls, add scroll-padding so the browser leaves space. Check cookie banners and chat widgets that sit over content.
Check focus order and traps
Focus should move in a logical order, and modals must keep focus inside while open and return it when closed. See accessible modals and popups and skip links and landmarks.
Test it
Put the mouse away and press Tab through your pages. Can you always see where you are? Can you reach and use everything? See accessibility testing tools for small sites.
Common mistakes
- Removing outlines without replacement
- Low-contrast focus rings on dark or colored sections
- Focus indicators that are hidden by overflow settings
- Custom widgets that cannot receive focus
Moving content can cause its own problems for keyboard users. Read accessible carousels and sliders.