Focus Styles for Different Element Types
You'll learn how different interactive elements need distinct focus indicator patterns to match user expectations.
Not all focusable elements are created equal. A link, a button, a text input, and a custom widget all serve different purposes, and their focus styles should reflect those differences while maintaining consistency and clarity.
Why Element Type Matters
Think of focus styles like uniforms for different professions: doctors, firefighters, and police officers all wear distinctive clothing so you immediately know their role. Similarly, different element types benefit from focus patterns that reinforce their function while remaining clearly visible.
Patterns by Element Type
Links typically receive subtle focus indicators since they're embedded in text. A thin outline or underline change works well:
a:focus-visible {
outline: 2px solid blue;
outline-offset: 2px;
}
Buttons are standalone controls and can handle bolder indicators:
button:focus-visible {
outline: 3px solid #0066cc;
outline-offset: 2px;
}
Form inputs often benefit from border-based styles that complement their structure:
input:focus-visible,
textarea:focus-visible {
outline: none;
border: 2px solid #0066cc;
box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.2);
}
Custom controls (elements with tabindex="0") need especially clear indicators since their interactive nature isn't obvious:
[role="button"]:focus-visible,
[tabindex="0"]:focus-visible {
outline: 3px solid #0066cc;
outline-offset: 3px;
box-shadow: 0 0 8px rgba(0, 102, 204, 0.5);
}
The key is consistency within each element type while ensuring all indicators meet minimum contrast and size requirements.
Key Takeaway: Match focus indicator style and prominence to the element type—subtle for inline links, bold for buttons and custom controls, and border-aware for form inputs—while maintaining clear visibility across all types.