Focus indicator

Also known as: focus ring

On this page 7

A focus indicator is the visible marker that shows which interactive element currently has keyboard focus on a web page, typically an outline, ring or highlight around a link, button or form field. In web accessibility, it is the element that tells keyboard, switch and voice users where their next keystroke will act.

Browsers draw a default indicator, often called a focus ring, but designers frequently restyle or remove it. Because a missing or faint indicator makes a page practically unusable without a mouse, the Web Content Accessibility Guidelines (WCAG) treat visible focus as a firm requirement rather than a styling preference.

How focus and the focus indicator work

At any moment, only one element in a document holds focus. Users move focus with the Tab and Shift+Tab keys, arrow keys inside composite widgets, or programmatic calls in scripts. The browser then applies the focus pseudo-classes to that element, and the stylesheet decides what the indicator looks like.

The table describes the CSS selectors that control when an indicator appears.

SelectorMatches whenTypical use
:focusThe element has focus by any meansBaseline styling, older browser support
:focus-visibleThe browser judges that focus should be shownKeyboard-only rings without mouse clutter
:focus-withinThe element or a descendant has focusHighlighting a whole form group or card
CSS selectors related to focus

The :focus-visible heuristic generally shows the indicator after keyboard navigation and on text inputs, but hides it after a mouse click on a button. This resolves the old conflict in which designers removed outlines because they disliked rings appearing on click, and in doing so broke keyboard navigation for everyone else.

WCAG requirements for focus visibility

Several WCAG success criteria govern focus indicators, and they differ in strictness. The baseline rule at level AA requires that focus is visible, while WCAG 2.2 added criteria about obscured focus and a measurable appearance standard.

CriterionLevelWhat it requires
2.4.7 Focus VisibleAAA keyboard focus indicator is visible
2.4.11 Focus Not Obscured (Minimum)AAFocused element is not entirely hidden by other content
2.4.12 Focus Not Obscured (Enhanced)AAANo part of the focused element is hidden
2.4.13 Focus AppearanceAAAMinimum size and 3:1 change in contrast
1.4.11 Non-text ContrastAAVisual parts of controls reach 3:1 contrast
WCAG success criteria that apply to focus indicators

The Focus Appearance criterion offers the most concrete target: the indicator should cover an area at least as large as a 2 CSS pixel thick perimeter of the element and show a contrast of at least 3:1 between focused and unfocused states. Even where only level AA is required, many teams adopt this measure because it removes guesswork from design reviews.

Designing an effective focus indicator

A strong indicator is thick, high-contrast and consistent across the interface. The most robust technique is a solid outline of 2 to 3 pixels with an outline-offset of about 2 pixels, which separates the ring from the element and keeps it readable on any background.

The following table compares common styling techniques.

TechniqueStrengthsWeaknesses
Outline with offsetFollows the element shape, no layout shiftSingle color may vanish on some backgrounds
Two-tone ringVisible on both light and dark surfacesSlightly more complex CSS
Box-shadow ringSmooth rounded appearanceDisappears in forced colors mode
Background color changeLarge, obvious areaMay fail contrast against nearby states
Underline or border changeSubtle, fits text linksOften too weak without other cues
Techniques for drawing a focus indicator

A two-tone indicator, for example a dark inner ring with a light outer ring, stays visible whether the element sits on white, black or a photograph. When box-shadow is used for appearance, adding a transparent outline ensures that Windows forced colors mode still draws a visible ring, because that mode removes shadows but repaints outlines in a system color.

The focus indicator is only the visual layer of keyboard accessibility. It works together with tab order, which decides the sequence of focusable elements, and focus management, which moves focus deliberately when content changes, such as opening a dialog or loading a new view.

A visible ring is of little use if focus lands somewhere unexpected. A skip link must be visible when focused, a focus trap in a modal must keep the indicator inside the dialog, and sticky headers or cookie banners must not cover the focused element, which is exactly what the WCAG 2.2 criterion on obscured focus addresses.

Common mistakes with focus indicators

Audits repeatedly find the same small set of focus failures, most of them introduced by global CSS resets or component libraries rather than by deliberate decisions.

MistakeEffect on usersFix
outline: none without replacementKeyboard users lose their positionRestore a custom :focus-visible style
Low-contrast ringIndicator invisible to low-vision usersReach at least 3:1 against adjacent colors
Indicator clipped by overflowRing cut off at container edgesUse offset inside or adjust overflow
Focus hidden under sticky headerFocused item scrolls out of viewUse scroll-padding-top on the page
Custom widgets not focusableNo indicator appears at allUse native elements or tabindex correctly
Frequent focus indicator failures
  • Test with the keyboard alone on every new template, tabbing through from top to bottom.
  • Check the indicator in forced colors mode and on every background color used in the design system.
  • Never rely on color change alone when the change is small or affects only thin text.

The short version

Many people move around websites with a keyboard instead of a mouse. They press Tab to jump from one link or button to the next. The focus indicator is the highlight that shows where they are. It works much like the blinking cursor in a document.

Without it, a keyboard user is like someone using a TV remote with no highlighted menu item. Every press does something, but they cannot see what. A clear, thick outline around the active item solves this. It also costs very little to design.

Where it makes a difference

A city council audits its online permit application form before a public launch. A tester with a motor impairment who navigates only by keyboard reports that after the third field she can no longer tell where she is. The cause is a CSS reset that removed outlines from every element.

The development team adds a 3 pixel two-tone outline with a 2 pixel offset through :focus-visible, adds scroll-padding so the sticky header no longer covers focused fields, and verifies a contrast of at least 3:1 on the white form and the dark blue footer.

On retesting, the same user completes the full application in under ten minutes without assistance, and the form passes the focus-related checks in the accessibility audit before launch.