Accessibility

a11y/focus-visible

Never remove the focus outline without drawing a visible replacement for keyboard focus.

seriousstaticWCAG 2.4.7 · AAfe-a11y-keyboard

Why

Keyboard users see where they are only through the focus indicator. outline: none on :focus with nothing in its place leaves them lost on the page.

Fix

Style :focus-visible instead of removing focus styles: button:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }. If the design needs no ring for mouse clicks, :focus:not(:focus-visible) { outline: none; } is acceptable. With Tailwind, pair outline-none with a focus-visible:ring-* or focus-visible:outline-* class.

Examples

/* bad */
button:focus { outline: none; }
/* good */
button:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

Sources

Facts

Id
a11y/focus-visible
Severity
serious
Check
static checked in the source by audit
Applies to
css scss less html angular vue svelte astro jsx
WCAG 2.2
2.4.7, level AA
Taught by the skill
fe-a11y-keyboard Keyboard access and focus
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain a11y/focus-visible