Focus Visible Outline Accessible
Style keyboard only focus indicators using focus-visible to show outlines only for keyboard navigation not mouse clicks.
Code
button:focus-visible,
a:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
outline: 3px solid var(--color-accent, #0066cc);
outline-offset: 2px;
border-radius: 4px;
}
button:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
outline: none;
}
.skip-link {
position: absolute;
left: -9999px;
}
.skip-link:focus-visible {
left: 1rem;
top: 1rem;
z-index: 1000;
}What the code does
Values that repeat across rules live in custom properties (--color-accent), so a theme change is one edit instead of a hunt through every rule.
State-dependent styling attaches through :focus-visible rather than class toggling from script.
The rules target outline: none; } .skip-link — each selector names the element it restyles, in source order.
Interactive Tools for This Topic
WCAG Color Contrast CheckerCalculate WCAG 2.1 color contrast ratios between foreground and background colors. Verify AA and AAA compliance levels for normal and large text accessibility.Tailwind Color Palette GeneratorGenerate a balanced 50-950 Tailwind CSS custom property color scale from any hex, RGB, or HSL base color with WCAG 2.1 contrast ratios for every stop.Argon2id Hash InfoEstimate Argon2id password-hash latency and memory usage, and check your parameters against OWASP 2024 minimum and recommended settings.bcrypt Cost EstimatorEstimate bcrypt cost factor latency and brute-force resistance, and get a recommended cost for your target hash time and attacker throughput.
FAQ
- Which elements does this stylesheet target?
- The rules bind to `outline: none; } .skip-link`; when two rules tie in specificity, the one written later in the file wins.
Report a problem with this exampleOpens a pre-filled issue on GitHub.