What is the :focus State?<\/h2>\r\n
When you want to click a button or link on a website, you move your mouse cursor over it and can see where you're pointing. You know you've found the right spot when the cursor appears over the button or link you've chosen. When using only the keyboard to activate a link or button, you can't see a mouse cursor because it's not in use—so you need an alternative visual indicator to show the user where they are.<\/p>\r\n
:focus is a state where an element in the interface becomes the center of action—meaning the user is focused on it in order to activate or interact with it. This typically happens when:<\/p>\r\n
- \r\n
- The user clicks on the element with a mouse<\/li>\r\n
- The user navigates to it using the keyboard (for example, with Tab)<\/li>\r\n
- The element receives focus programmatically through JavaScript<\/li>\r\n<\/ul>\r\n
When an element is in :focus state, the browser displays a visual indicator—usually a blue border or underline—that shows the user where they are on the page.<\/p>\r\n
Why is :focus Important for Accessibility?<\/h2>\r\n
For many users, especially:<\/p>\r\n
- \r\n
- People who navigate using only the keyboard<\/li>\r\n
- Users with motor disabilities<\/li>\r\n
- Blind users who rely on screen readers<\/li>\r\n
- Those who struggle with mouse use (including touch users)<\/li>\r\n<\/ul>\r\n
The ability to know \"where am I?\" in an interface is critical. Focus is their way to navigate, orient themselves, and use a website independently.<\/p>\r\n
Common Mistakes That Harm Accessibility<\/h2>\r\n
- \r\n
- Completely removing the outline<\/strong>
Many designers remove the default focus outline for aesthetic reasons. This prevents users from identifying where they are and violates accessibility standards (WCAG 2.1—Section 2.4.7).<\/li>\r\n- Styling only for hover, not focus<\/strong>
Interactive styling that only responds to :hover and not :focus is inaccessible to keyboard users.<\/li>\r\n- Interactive elements that don't receive focus<\/strong>
For example: a <div> or <span> with interactive functions but no tabindex=\"0\" attribute—these are keyboard inaccessible.<\/li>\r\n<\/ol>\r\nPractical Recommendations for Using :focus<\/h2>\r\n
- \r\n
- Always preserve a clear focus indicator<\/strong>
If you're redesigning focus styling, make it visually distinct and obvious:<\/li>\r\n- Don't use outline: none without a clear replacement<\/strong>
Removing focus completely prevents users from navigating your site.<\/li>\r\n- Add tabindex=\"0\" to custom interactive components<\/strong>
Elements that aren't keyboard-accessible by default but serve an interactive function (like <div role=\"button\">) need explicit focus.<\/li>\r\n- Ensure focus is visible even in high-contrast mode<\/strong>
Users who enable High Contrast mode on their operating system often rely on outline visibility, as other colors may disappear.<\/li>\r\n<\/ul>\r\nIn Summary<\/h2>\r\n
The :focus state is a cornerstone of digital accessibility. It's not a design feature—it's a fundamental need that enables users to navigate, orient themselves, and take action. Proper focus design improves the user experience for everyone.<\/p>
- Don't use outline: none without a clear replacement<\/strong>
- Styling only for hover, not focus<\/strong>
- Completely removing the outline<\/strong>