Keyboard Navigation WCAG: A Practitioner's Guide

Keyboard Navigation WCAG: A Practitioner's Guide

Getting the keyboard path right removes a barrier many assistive technologies share. Tab order, focus management, modal traps, route-change restoration, and the ARIA keyboard contracts.

Five core WCAG success criteria govern keyboard accessibility — 2.1.1, 2.1.2, 2.1.4, 2.4.3, and 2.4.7 — and WCAG 2.2 adds three more on focus visibility (2.4.11, 2.4.12, and 2.4.13). Getting the keyboard path right removes a barrier that many assistive technologies share. This guide covers tab order rules, focus management for modals and route changes, the visible focus contract, skip links, and the keyboard contracts the ARIA Authoring Practices Guide expects for custom widgets.

Why keyboard accessibility is the load-bearing WCAG requirement

Many assistive technologies rely on the same focus and keyboard interfaces that keyboard users do. Screen reader users navigate with the keyboard, and some switch setups move through a page by sending Tab and Enter. Voice control software such as Voice Control on macOS lets users act on onscreen items by saying their names; when a control has no usable name, users have to fall back to number labels or an on-screen grid, so unlabeled controls slow them down too. If the keyboard path through your site is broken, many other assistive technologies break with it. If the keyboard path works, one barrier that many assistive technologies share is removed.

Keyboard access is necessary but not sufficient. WCAG places the core keyboard criteria (2.1.1, 2.1.2, 2.1.4) at Level A, and keyboard issues are a frequent finding in manual audits. Automated scans such as the WebAIM Million 2024 count keyboard-related markup — the 2024 report tracks skip links and tabindex use — but the report does not say whether functionality works from the keyboard, and it notes that not all conformance failures can be detected automatically. That is why manual keyboard testing matters.

A short pass of Tab and Shift+Tab through a representative flow finds keyboard issues that automated tools cannot reliably detect, and the fix patterns are well-documented. The work is recognizing the bug, not solving a research problem.

The keyboard success criteria that matter

Five core WCAG success criteria cover the keyboard surface, and three WCAG 2.2 additions tighten visible focus.

CriterionLevelWhat it requires
2.1.1 KeyboardAAll functionality operable via keyboard, without keystroke timing, except functions that need path-dependent input
2.1.2 No Keyboard TrapAKeyboard focus can leave any component it can reach, using only the keyboard; non-standard exits must be explained
2.1.4 Character Key ShortcutsACharacter-key-only shortcuts: at least one of switchable off, remappable, or focus-scoped
2.4.3 Focus OrderAWhere sequential navigation affects meaning or operation, focus order preserves meaning and operability
2.4.7 Focus VisibleAAKeyboard-operable UI has a mode of operation where the keyboard focus indicator is visible
2.4.11 Focus Not Obscured (Min)AA (2.2)Focused element not entirely hidden by author content
2.4.12 Focus Not Obscured (Enhanced)AAA (2.2)No part of the focused element hidden by author content
2.4.13 Focus AppearanceAAA (2.2)Indicator area at least a 2 CSS px perimeter, 3:1 focused vs unfocused; exceptions for browser-default indicators

SC 2.1.1 Keyboard is the load-bearing one. All functionality must be operable through a keyboard interface without requiring specific timings for individual keystrokes, except where the underlying function needs input that depends on the path of the user's movement — free-form drawing, for example, but not handwriting used to enter text, because the underlying function there is text input. A drag-and-drop interaction that has no keyboard equivalent fails 2.1.1 when only the drop location matters, not the path of the drag. Separately, the new WCAG 2.2 SC 2.5.7 Dragging Movements (AA) requires a single-pointer alternative without dragging, such as tap-to-select, unless dragging is essential or the functionality is determined by the browser and not modified by the author — and a keyboard equivalent alone does not satisfy it.

SC 2.1.2 No Keyboard Trap prevents the user from getting stuck in a component. A typical trap is a custom widget or modal that captures Tab and offers no keyboard way out — no reachable close button and no Escape handler — so the user can only leave with a mouse. Escape is the expected exit for a modal, but 2.1.2 itself requires only that focus can be moved away using the keyboard alone — and, if that takes more than unmodified arrow or Tab keys or other standard exit methods, that the user is told how.

SC 2.1.4 Character Key Shortcuts (new in WCAG 2.1) targets shortcuts a page implements using only character keys — letters, punctuation, numbers, or symbols — such as pressing "j" to scroll down a feed. Such shortcuts can be fired by accident by speech input users and by keyboard users with dexterity challenges. Compliance requires at least one of three mechanisms: a way to turn the shortcut off, a way to remap it to include one or more non-printable keys such as Ctrl or Alt, or scoping it so it only fires when the relevant element has focus.

SC 2.4.7 Focus Visible at Level AA requires that any keyboard-operable user interface have a mode of operation where the keyboard focus indicator is visible. The criterion itself does not specify thickness or contrast. Contrast against adjacent colors comes from SC 1.4.11 Non-text Contrast at Level AA, which requires a contrast ratio of at least 3:1 for an author-styled indicator (not for a browser-default indicator the author has not modified), while the indicator's size and its focused-versus-unfocused contrast are quantified in the WCAG 2.2 SC 2.4.13 Focus Appearance at Level AAA. Even so, removing the default browser outline (outline: none) without a replacement is a common, well-documented SC 2.4.7 failure.

Tab order: the rules and the trap

DOM order is the default tab order. Browsers walk the document in source order, focusing each interactive element (button, a[href], input, select, textarea, [tabindex="0"], and a handful of others) in the order they appear in the HTML. The first rule of tab order is to arrange interactive elements in the source so the visual sequence matches the document sequence. CSS positioning that visually rearranges elements without rearranging the DOM is a common source of focus order bugs.

tabindex modifies this. tabindex="0" makes a non-interactive element focusable at its DOM position — useful for <div role="button"> (rare and usually wrong). tabindex="-1" removes from the tab order but allows programmatic focus via JavaScript — the right setting for elements you want to focus from code (a heading after route change, or a skip-link target) but not via Tab.

Positive tabindex values (tabindex="1", tabindex="2", etc.) override DOM order globally. The ARIA Authoring Practices Guide strongly discourages positive tabindex values. Once any element has a positive tabindex, every interactive element in the page is sorted by its tabindex value first and DOM order second — so adding a new component anywhere in the page can shift the entire focus sequence in ways that are hard to predict and harder to test.

html
<!-- The roving tabindex pattern: only one element in the group has
     tabindex='0' at a time. Arrow keys move within the group; Tab
     moves to the next group. Used by toolbars, listboxes, tabs. -->
<div role="toolbar" aria-label="Text formatting">
  <button tabindex="0">Bold</button>
  <button tabindex="-1">Italic</button>
  <button tabindex="-1">Underline</button>
</div>

Roving tabindex is one of the two focus-management techniques the ARIA Authoring Practices Guide describes for composite widgets — toolbars, tab interfaces, listboxes, and menus (the other is aria-activedescendant). Only one element in the group has tabindex="0" at a time; the others are tabindex="-1". Tab moves into and out of the group as a single unit; arrow keys move within the group, with the JavaScript handler updating which element holds the tabindex="0". This matches the keyboard model users expect and keeps the page-level Tab sequence concise.

Focus management for modals, menus, and route changes

Single-page applications introduce a focus management surface that traditional multi-page applications get for free. Every time a route changes, focus must move somewhere predictable; otherwise the keyboard user is left at the link they clicked while the visible page has changed entirely.

typescript
'use client'
// Route-change focus restoration in a Next.js App Router app.
// Move focus to the page heading on every route transition.
import { useEffect, useRef } from 'react'
import { usePathname } from 'next/navigation'

export function PageHeading({ children }: { children: React.ReactNode }) {
  const ref = useRef<HTMLHeadingElement>(null)
  const pathname = usePathname()
  useEffect(() => {
    ref.current?.focus()
  }, [pathname])
  return (
    <h1 ref={ref} tabIndex={-1}>
      {children}
    </h1>
  )
}

The pattern is identical in React Router (use a useEffect on useLocation) and in Vue Router (use the afterEach navigation guard). The destination must have tabindex="-1" because headings are not natively focusable, and the focus move should be paired with an aria-live="polite" region that announces the new page title for screen reader users who already know how to navigate by heading.

The modal pattern has its own contract: focus moves into the modal on open, traps inside while open, returns to the trigger on close (unless the trigger no longer exists or the workflow makes another element the more logical target), Escape closes. The traditional implementation of the focus trap was manual — listen for Tab and Shift+Tab, intercept and redirect when focus would leave the modal. The modern implementation uses the inert attribute to mark every sibling of the modal as inert, removing them from the tab order and the accessibility tree in one declarative move. inert is supported in all major browsers as of 2023.

Better still, the native <dialog> element handles inert internally when opened with showModal(). For most modal use cases in 2026, <dialog> plus a small amount of CSS is the right pattern — it covers the focus trap and the Escape handler without requiring a focus-management library; closing on a backdrop click is not the default and needs a small click handler — or the closedby="any" attribute, which Chrome, Edge, and Firefox support but Safari does not (as of Oct 2026, web-features).

Menu and combobox patterns differ from the modal pattern in keyboard contract. In a menu (per the ARIA Authoring Practices Guide), Tab moves out of the widget rather than between menu items; arrow keys move within. In a combobox (APG combobox pattern), Down arrow opens, arrows navigate the listbox, Enter commits the selection, Escape cancels. Implementing a menu with Tab between items breaks the keyboard model users know from desktop application menus.

Visible focus — what passes SC 2.4.7 and what doesn't

Removing the default browser outline without replacement is a common SC 2.4.7 failure. The pattern is recognizable in production CSS:

css
/* SC 2.4.7 failure: outline removed with no replacement */
button:focus { outline: none; }

/* Correct: keep the ring when the browser shows focus (typically keyboard), suppress it otherwise */
button:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
button:focus:not(:focus-visible) { outline: none; }

The :focus-visible pseudo-class is the modern way to show focus when the browser's heuristics judge it helpful — typically for keyboard focus — and to hide it when, for example, a button is clicked with a mouse. Designers often want the latter; the historical pattern of outline: none followed by some hand-rolled JavaScript focus-detection has been obsoleted by :focus-visible in every major browser.

A custom focus ring must be visible against every background it can appear on. This often forces a focus token that uses a high-contrast color the design system reserves for the purpose, with sufficient offset so the ring is clearly outside the element rather than absorbing into it. The interaction with SC 1.4.11 Non-text Contrast is direct: the focus ring must contrast at least 3:1 against the colors adjacent to it. Contrast between the focused and unfocused states is a separate, Level AAA requirement in SC 2.4.13.

WCAG 2.2 SC 2.4.11 Focus Not Obscured (Minimum) at Level AA tightens the bar further. The focused element must not be entirely hidden by author-created content — sticky headers and footers, cookie banners, and non-modal dialogs are typical violators. One mitigation (WCAG technique C43) is CSS scroll-padding on the root scroll container, sized to the sticky element — scroll-padding-top for a sticky header, scroll-padding-bottom for a bottom banner:

css
/* When focus moves to an anchor or programmatically scrolled target,
   leave room for the sticky header so the focused element is not
   hidden behind it. */
html { scroll-padding-top: 64px; }

WCAG 2.2 SC 2.4.13 Focus Appearance at Level AAA quantifies the focus indicator: when the keyboard focus indicator is visible, an area of it must be at least as large as the area of a 2 CSS pixel thick perimeter of the unfocused component or sub-component, with at least a 3:1 contrast ratio between the same pixels in the focused and unfocused states (a solid 2 CSS pixel perimeter is the simplest way to meet the size requirement; the 3:1 change still has to be met). The criterion does not apply where the indicator is determined by the browser and cannot be adjusted by the author, or where the author has not modified the indicator or its background color. This is appropriate as a design system aspiration on focus tokens but is not required at AA.

Skip links and landmarks

SC 2.4.1 Bypass Blocks at Level A requires a way for keyboard users to skip past repeated navigation. The canonical implementation is a "Skip to main content" link as the first focusable element on every page. The link is typically visually hidden until focus, then revealed:

html
<a href="#main-content" class="skip-link">Skip to main content</a>

<style>
  .skip-link {
    position: absolute;
    left: -9999px;
  }
  .skip-link:focus {
    left: 1rem;
    top: 1rem;
  }
</style>

Current browsers move the sequential focus starting point to the skip link target, so the next Tab continues from there. Many teams still add tabindex="-1" to the target so focus itself lands on it; test with the assistive technologies you support.

ARIA landmarks (main, navigation, banner, contentinfo) and the HTML elements that provide them (<main>, <nav>, and page-level <header> and <footer>) let assistive tech jump between regions without reading every interactive element in between. Screen readers expose a landmark navigation mode that depends on these. A page with a single <header>, <nav>, <main>, and <footer> lets screen reader users jump cleanly; a page with three unlabeled <nav> elements creates ambiguity that a unique label on each (aria-label or aria-labelledby) resolves.

Custom widgets — the ARIA Authoring Practices keyboard contracts

The ARIA Authoring Practices Guide documents the keyboard contracts users expect for each custom widget pattern. Building a custom widget that diverges from these contracts is technically allowed but creates friction for assistive technology users, who cannot transfer what they learned on other sites.

PatternOpenNavigateActivateClose
DisclosureEnter / Space——Enter / Space
Listbox—Arrow keys, Home/End, typeaheadSpace (multi-select) or selection follows focus—
ComboboxDown arrowArrow keysEnterEscape
Tabs—Arrow keys, Home/End(auto on focus, or Space/Enter)—
Dialog(programmatic)Tab within(button-specific)Escape
MenuEnter / Space (Down arrow optional)Arrow keys, typeaheadEnterEscape

The Tabs pattern has a subtlety worth noting: arrow keys switch between tabs, and APG recommends that the panel activate as the tab receives focus when it can be displayed without noticeable latency (APG also allows manual activation with Space or Enter when panels are slow to load). Tab key moves into and out of the tab panel, not between tabs. The opposite implementation — Tab between tabs and arrow within the panel — is a common mistake that breaks user expectations.

For a Dialog, focus moves into the dialog on open, traps inside, Escape closes, focus returns to the trigger (or to another logical element if the trigger no longer exists or the workflow calls for it). The combination of <dialog> with showModal() and inert on siblings handles all of this in modern browsers; older codebases use focus-trap libraries (focus-trap, focus-trap-react) for the same effect.

Test criteria for your engineering team

The keyboard audit is an inexpensive accessibility test that catches many regressions. As a planning rule of thumb rather than a measured figure, allocate about two hours.

  • Press Tab from the page top through to the footer — every interactive element receives focus, the focus indicator is visible at each stop, order matches visual sequence
  • Press Shift+Tab from the footer back up — the same elements are reachable in reverse without the order changing
  • On every modal and menu — focus moves in on open, traps inside, returns on close, Escape closes
  • In a single-page app — after route change, focus is on the new page's primary heading or skip target, not stuck on the old page
  • On every form — Enter submits where expected, Space toggles checkboxes and buttons, Tab moves between fields without skipping or repeating
  • On every custom widget — keyboard contract matches the ARIA Authoring Practices Guide pattern users expect (Listbox, Combobox, Menu, Tabs, Disclosure)
  • With sticky headers and cookie banners visible — Tab through a long form and confirm no focused field is entirely hidden behind sticky content (SC 2.4.11)

If a check fails, the fix is at the component level — a Tab order bug often comes from a shared component rather than a single page. Update the component, the design system token, or the framework wrapper, then re-run the audit.

Project Inquiry