الانتقال إلى المحتوى
FrontendAccessibility· 6 دقائق للقراءة

outline: none Locks Out Keyboard Users: Focus Styles Done Right

The focus ring is the keyboard user's cursor. Restyle it with :focus-visible instead of deleting it.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
  • WCAG 2.2
محتويات المقال

A designer reviewing the new account page complains about the blue rings around fields and buttons: "they look like a bug". A developer adds *:focus { outline: none; } to the base stylesheet, and the ticket is closed. Two weeks later, a customer who navigates with the keyboard reports that the page "does random things". He pressed Enter on what he believed was "Save", but focus was two controls further, on "Delete address". Nothing on the screen showed him where he was.

The common misconception

The belief: the focus outline is decoration the browser adds, and removing it is a style decision, like changing a font.

For mouse and touch users it mostly is noise. They already know what they clicked, and MDN itself says focus styles aren't required when the user sets focus with a pointer. outline: none also shows up in plenty of CSS snippets and resets, so it looks like standard practice. And whoever tests the change with a mouse sees nothing break, because for them nothing does.

What actually happens

Focus is the keyboard user's cursor

Keyboard users move through a page with Tab and Shift+Tab, and every key they press acts on the element that has focus. The is the only way they can see which element that is. The same is true for people who use speech input, sip-and-puff devices or scanning software: WCAG's Understanding document for 2.1.1 Keyboard lists them as keyboard emulators, so keyboard access serves them too.

That's why WCAG 2.2 makes it a requirement. Success criterion 2.4.7 Focus Visible (Level AA) says: "Any keyboard operable user interface has a mode of operation where the keyboard focus indicator is visible." Its Understanding document lists, as failure F78, styling outlines and borders in a way that removes the visual focus indicator or makes it invisible.

The browser already hides it from the mouse

The default ring generally follows :focus-visible, not :focus. MDN describes :focus-visible as matching when the browser's heuristics decide that focus should be made evident, and notes that many browsers show their focus ring in exactly that case. We checked three cases in headless Chromium:

  • Mouse click on a button: :focus matched, :focus-visible didn't, and no ring was drawn.
  • Mouse click into a text field: :focus-visible matched and the ring showed, since you need to see where typing goes.
  • Tab to the same button: :focus-visible matched and the ring showed.

So the default behavior already gives mouse users most of what the designer asked for, without taking anything away from keyboard users.

outline: none removes it for everyone

*:focus matches every kind of focus, keyboard focus included. With that rule in place, tabbing to the button in Chromium left it with outline-style: none: focus moved, and nothing on the screen changed.

Visible also means not covered

WCAG 2.2 added 2.4.11 Focus Not Obscured (Minimum), Level AA: "When a user interface component receives keyboard focus, the component is not entirely hidden due to author-created content." Sticky headers, cookie banners and non-modal dialogs are the usual offenders.

We tested it with an 80px sticky header above a long list of links. Pressing Shift+Tab from the bottom of the page back up, 9 of the 41 focus stops landed right under the header, where a hit test at the center of the focused element returned the header instead. With scroll-padding-top: 80px on html, the approach WCAG documents as technique C43, none of them did.

CSS base.css
/* "Remove the ugly ring" */*:focus {  outline: none;}

Rendered in headless Chromium, the right version draws a 3px solid ring when you Tab to a control or click into a text field, draws nothing when you click a button with the mouse, and keeps every focused element visible below the header.

MythReality
The ring is a visual glitchIt's the keyboard user's cursor, and WCAG requires it (2.4.7, Level AA)
Mouse users always see itThe default ring follows :focus-visible, which skips most mouse clicks on buttons
outline: none only changes the lookIt removes keyboard focus too; WCAG lists it as failure F78
Any visible change will doA faint ring fails people with low vision; MDN cites a 3:1 contrast requirement
A focused element is always on screenSticky headers and banners can cover it; 2.4.11 (new in WCAG 2.2) forbids that

How to apply it in your project

  1. Find every removalSearch your CSS and any reset you import for outline: none and outline: 0 on :focus selectors. Delete them, or move the custom styling to :focus-visible.
  2. Define one strong indicatorWrite a single :focus-visible rule with a thick outline and an offset, in a color with at least 3:1 contrast against every background it sits on. Override it per component only when a background requires it.
  3. Make room for sticky UISet scroll-padding-top and scroll-padding-bottom on html to the height of your sticky header and footer, and make sure cookie banners can't cover the element that has focus.
  4. Tab through every pagePut the mouse away and walk each page with Tab and Shift+Tab. Every stop needs a visible, uncovered ring. Repeat once in forced colors mode, using a Windows contrast theme or the forced-colors emulation in your browser's DevTools.

Key takeaways

  • The focus indicator is the keyboard user's cursor; removing it fails WCAG 2.4.7 Focus Visible (Level AA).
  • :focus matches every focus, while :focus-visible matches only when the browser decides focus should be shown.
  • Restyle :focus-visible with a thick, high-contrast outline instead of deleting the ring.
  • A visible ring must also stay uncovered: WCAG 2.2's 2.4.11 targets sticky headers and banners, and scroll-padding fixes most cases.
  • Prefer outline over box-shadow: it doesn't shift the layout and it survives forced colors mode.

📚 المصادر

  1. Understanding SC 2.4.7: Focus Visible — WCAG 2.2 (W3C WAI)
  2. Understanding SC 2.1.1: Keyboard — WCAG 2.2 (W3C WAI)
  3. Understanding SC 2.4.11: Focus Not Obscured (Minimum) — WCAG 2.2 (W3C WAI)
  4. :focus-visible — MDN
  5. forced-colors — MDN

التعليقات (0)