Barrierepruefung.de Web Accessibility Checker

Focus is not visible

The finding means nothing about this element changes when it receives focus with the Tab key, neither its style nor its rendering. Usually a style sheet switched off the browser's focus ring with outline: none and put nothing in its place. Add a rule for :focus-visible with a clear outline.

Last reviewed: Sources

The message

Identifier
own.focus-not-visible
Type of check
automatic
Severity
serious
Success criterion
Meaning
When tabbing to this element nothing changes visibly. Neither its style nor its rendering differs from the unfocused state.
Impact
People operating the page by keyboard no longer know where they are, and press Enter blind.
Fix
Do not switch off the focus indicator. Where custom styling is wanted, replace it with a clearly visible outline or shadow.

How does your website stand?

The free check shows what can be measured automatically, with the location. No account.

Check website for free

What the rule checks

The check operates the page in the desktop window with real presses of the Tab key, starting at the top of the document, the way someone without a mouse would. Beforehand it records every focusable element in its unfocused state.

At each stop it first compares the element's style, including ::before and ::after: outline, border, shadow, background and text colour, background image, filter, transform and text decoration. If any of these changes, focus counts as visible. If nothing changes, it compares a picture of the element plus a small margin with and without focus. This also catches an indicator drawn by a parent element, for instance through :focus-within. If both pictures are identical, the rule reports the element.

The number of picture comparisons per page is capped. Once the cap is reached, an element takes over the result of an identically built element that was already decided by picture. If the result stays open, that is not a defect but a gap in the measurement, which the report names at the criterion. Whatever sits inside an iframe or a shadow DOM is not judged by this rule.

The rule only catches the case where nothing changes at all. Focus that changes but is barely noticeable passes this rule and can still fail the criterion.

Common causes

  • Focus ring switched off. A reset or theme style sheet contains *:focus { outline: none; } or a:focus { outline: 0; }, and no other rule draws a replacement. The W3C lists this as a failure (F78).
  • Only the mouse state is designed. :hover gets a colour or an underline, :focus gets nothing.
  • Overridden by a more specific rule. A general focus style exists, but .btn:focus { outline: none; box-shadow: none; } from a library cancels it for buttons.
  • Custom controls. A div with tabindex="0" and outline: none acting as a button or tab.

How to fix it

Keep the browser's focus ring or replace it, rather than just switching it off. :focus-visible shows the outline for keyboard use and leaves it out on mouse clicks (C45):

/* before */
*:focus {
  outline: none;
}

/* after */
:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 2px;
}

An indicator made of two colours stays visible on light and dark surfaces alike (C40):

:focus-visible {
  outline: 2px solid #f9f9f9;
  outline-offset: 0;
  box-shadow: 0 0 0 4px #193146;
}

If you draw focus with box-shadow only, add a transparent outline. In Windows contrast themes shadows are dropped, while the outline is shown in the system colour:

.button:focus-visible {
  box-shadow: 0 0 0 3px #1d4ed8;
  outline: 2px solid transparent;
}

Search your style sheets for outline: none, outline: 0 and outline-width: 0 in rules for :focus. Each match needs either a replacement in the same rule or a :focus-visible rule that is more specific.

What the criterion requires in detail is explained on the page about WCAG 2.4.7.