WSS
Web Specification Studio Home

Focus & Keyboard Accessibility Lab

Interactive laboratory for designing and validating keyboard focus indicators. Test compliance with WCAG 2.2 SC 2.4.11 (Focus Not Obscured, Level AA) and SC 2.4.13 (Focus Appearance, Level AAA) with live viewport obstruction simulation.

Focus state parameters updated.

Indicator Styling

3px
2px

SC 2.4.11 / 2.4.12 Obstruction Simulator

Tests whether keyboard focus remains visible when elements scroll near a fixed/sticky header.

Fixed Sticky Header (z-index: 10)Sticky Zone

Use Tab to jump between these controls:

Remedy: Add scroll-padding-top: var(--header-height); to the scroll container or scroll-margin-top to target elements to prevent sticky headers from hiding focused controls.

WCAG 2.2 SC 2.4.13 Focus Appearance

Level AAA Normative Indicator Criteria
PASS LEVEL AAA
1. Indicator Area
Actual:1140px²
Required:736px²
Result:PASS
2. Contrast Change
Ratio:4.73:1
Threshold:3.00:1
Result:PASS
vs. unfocused state
3. Adjacent Surface
Ratio:6.70:1
Threshold:3.00:1
Result:PASS
vs. background surface

Interactive Tabbable Playground

Press Tab and Shift+Tab to inspect the generated focus ring on live controls:

Accessible Link

Production-Ready CSS Snippet

/* WCAG 2.2 Accessible Focus Indicator */
:focus {
  outline: none; /* Suppress browser default only when replaced */
}

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

/* Ensure focus remains visible under reduced motion and high contrast */
@media (forced-colors: active) {
  :focus-visible {
    outline: 2px solid Highlight;
  }
}
Testing Notice:Automated geometry and contrast checks evaluate isolated indicator styling only. They cannot determine whether dynamic viewport scrolling, sticky navigation bars, CSS overflow:hidden, or modal overlays obscure the indicator in a real application. Manual keyboard navigation audits (Tab / Shift+Tab) across all target browsers are required to confirm WCAG 2.2 SC 2.4.11 / 2.4.12 compliance.
CSS Architecture

The Three Physical Layers of a Compliant Focus Indicator

Crafting focus indicators that satisfy WCAG 2.2 Level AAA requirements requires understanding how browser rendering engines composite outlines, offsets, and element borders.

01

Element Surface Boundary

The base component border and border-radius. WCAG 2.2 SC 2.4.13 calculates the minimum required perimeter area based on this bounding box (perimeter length multiplied by 2px).

02

The Separation Gap (Offset)

Setting outline-offset to 2px or 3px creates visual breathing room. Without an offset, a blue focus indicator on a dark blue button creates an unreadable color wash that fails the 3:1 contrast rule.

03

Solid Perimeter Indicator

The visible ring itself. Using a solid line at 2px or 3px width guarantees that the surface area requirement is met without relying on complex box-shadow hacks.

Production Pitfalls

Three Common Keyboard Traps and Native Fixes

Real accessibility failures often occur in interactive state transitions where keyboard focus becomes trapped or obscured.

Trap 1: Leaking Modals

Modal Backdrop Escapes

Pressing Tab inside an open modal leaks focus to background links behind the overlay.

Fix: Use native dialog.showModal() or inert on body siblings.
Trap 2: Off-Screen Items

Hidden Carousel Cards

Tabbing into hidden slider slides scrolls the browser window erratically.

Fix: Apply visibility: hidden or inert to inactive carousel slides.
Trap 3: Container Clipping

Overflow Hidden Clipping

Cards with overflow: hidden cut off standard CSS outlines on child buttons.

Fix: Use outline-offset: -2px to draw the focus ring inside the border.
Rendering Quirks

Cross-Engine Focus Behavior Matrix

Browser EngineDefault Outline StyleMouse Click on Button:focus-visible Support
Chromium (Blink)Black/white double ring (auto 1px outline).Suppresses ring on mouse click.Full native support
Safari (WebKit)Accent color glow ring.Requires Option+Tab for full tab navigation unless enabled in system settings.Full native support
Firefox (Gecko)Thin dotted ring or solid blue indicator.Suppresses ring on mouse click.Full native support
Knowledge Base

Frequently Asked Questions

Concise answers regarding keyboard navigation, focus indicators, and WCAG 2.2 compliance.

Why should developers use focus-visible instead of focus?
:focus-visible only activates when a user navigates via keyboard (Tab key) or assistive tech, preventing unwanted focus rings on mouse clicks while guaranteeing full visibility for keyboard navigators.
How does outline-offset prevent focus ring clipping in CSS?
outline-offset pushes the focus indicator outside the element box. On overflow-clipped containers, setting a negative outline-offset draws the ring inside the element border, preventing parent overflow:hidden from clipping the indicator.
How do you trap keyboard focus in modal dialogs without third-party libraries?
Use the native HTML dialog element with the showModal() method. Modern browsers automatically trap keyboard Tab navigation within the active dialog and prevent focus from leaking to background content.
What is the minimum physical size for a WCAG 2.2 focus indicator?
WCAG 2.2 SC 2.4.13 requires an area at least equal to a 2px solid perimeter around the unfocused element, with at least 3:1 contrast against adjacent background colors.