Why focus indicators are crucial
Any interactive element must have a focus indicator to let keyboard-only users know where they are on the page. Focus indicators are essential for:- Keyboard navigation - Users who navigate with Tab/Shift+Tab need to see where they are
- Motor disabilities - Users who cannot use a mouse rely entirely on keyboard navigation
- Screen reader users - Visual focus indicators help sighted screen reader users track their position
- Power users - Many users prefer keyboard navigation for efficiency
- Temporary limitations - Broken mouse, touchpad issues, or situational constraints
The classic outline
By default, browsers provide a focus outline on interactive elements. While this outline might not match your design, it serves a critical accessibility function.Never use
outline: none without providing an alternative focus indicator. This is one of the most common accessibility mistakes.Common anti-pattern
Using :focus-visible
The:focus-visible pseudo-class is a modern solution that shows focus indicators only when needed - typically for keyboard navigation, not for mouse clicks.
:focus-visible is supported in all modern browsers. For older browser support, include both :focus and :focus-visible rules.Different ways to show focus
This doesn’t mean that we MUST use the
outline to show focus. There are all kinds of ways to show a focus indicator.1. No indicator (bad example)
This example demonstrates what NOT to do. Always provide a visible focus indicator.
2. Classic outline
The traditional approach using theoutline property:
3. Background color change
Change the background and text color on focus:4. Box shadow
Use box-shadow for a softer, modern focus indicator:5. Text styling
Change text appearance for focus indication:6. Transform effect
Use subtle transforms to indicate focus:Interactive demo from the course
The introduction page includes a live demonstration of these different focus indicator styles:Try navigating these buttons with the Tab key to see how different focus indicators behave.
Best practices for focus indicators
Ensure sufficient contrast
Ensure sufficient contrast
Focus indicators must have a contrast ratio of at least 3:1 against adjacent colors (WCAG 2.2).
Make them visible
Make them visible
Focus indicators should be easily noticeable. Subtle differences in color or style may not be enough.
Keep consistent
Keep consistent
Use a consistent focus indicator style throughout your application so users know what to expect.
Don't rely on color alone
Don't rely on color alone
Combine color changes with other visual cues like outlines, borders, or transforms.
Consider offset
Consider offset
Use
outline-offset to create space between the element and the focus indicator for better clarity.Test with keyboard only
Test with keyboard only
Navigate your entire site using only the Tab key. Can you always see where you are?
Working with design teams
Always make sure your interactive components have visible focus indicators.Tips for design collaboration
Include focus states in designs
Ask designers to include focus states in their mockups alongside hover and active states.
Explain the requirement
Help designers understand that focus indicators are not optional - they’re an accessibility requirement.
Offer creative solutions
Share examples of beautiful, on-brand focus indicators that match your design system.
Test together
Demonstrate keyboard navigation to your design team. Seeing the experience firsthand helps build understanding.
Focus management for custom components
When building custom interactive components, you need to manage focus properly:Custom buttons
If you must use a<div> or <span> as a button (though you should prefer native <button> elements):
Modal dialogs
When opening a modal, trap focus within it:Skip links
Provide skip links to help keyboard users bypass repetitive content:Common focus indicator mistakes
- Removing outlines globally - Never use
* { outline: none; }in your CSS - Only styling :hover - Focus states need styling too, not just hover states
- Insufficient contrast - Focus indicators that are barely visible don’t help users
- Missing focus on custom components - All interactive elements need focus indicators
- Breaking focus order - Using CSS positioning or JavaScript incorrectly can break the natural tab order
- Forgetting focus within components - Accordions, tabs, and other composite widgets need internal focus management
Testing your focus indicators
Testing checklist
- Tab through your entire page - Can you see where focus is at all times?
- Check contrast - Do focus indicators have sufficient contrast (3:1 minimum)?
- Test on different backgrounds - Focus indicators should work on all background colors
- Test with zoom - Focus indicators should remain visible at 200% zoom
- Try different browsers - Focus styles can vary between browsers
- Use browser DevTools - Chrome and Firefox have accessibility inspectors that highlight focus
- Get feedback from keyboard users - Real user testing is invaluable