Focus Visible Outline Accessible

Style keyboard only focus indicators using focus-visible to show outlines only for keyboard navigation not mouse clicks.

CssSecurity Boundaries

Code

csssnippet
24 lines
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

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.