Skip to content

Chapter 4 of 8

Keyboard Navigation and Focus Management

Keyboard accessibility is essential because many users, including those who are blind or have motor impairments, rely entirely on the keyboard to interact with the web. The tab order is the sequence in which focus moves through interactive elements via the Tab key, and ideally this order follows the natural DOM order so that visual layout matches logical progression. The tabindex attribute controls focusability: tabindex="0" makes an element focusable in DOM order, tabindex="-1" allows programmatic focus without including the element in sequential tab navigation, and positive tabindex values should be avoided because they disrupt natural order and are difficult to maintain.

Visible focus is critical because it tells keyboard users which element is currently active. Removing focus outlines or replacing them with an invisible alternative silently breaks the experience for keyboard users. The CSS :focus-visible pseudo-class improves on the older :focus selector by showing a focus ring only when the browser determines the user is navigating by keyboard, which keeps mouse interactions visually clean while still satisfying keyboard users. Modern focus indicators should be clearly visible and meet WCAG contrast requirements so they are easy to spot against any background.

Many components require explicit focus management because the browser cannot infer what should happen when content changes. When a modal opens, focus should move to the first focusable element inside, ideally the heading or a primary action, and a focus trap should constrain Tab and Shift+Tab to cycle within the modal. Pressing Escape should close the modal, and when it closes, focus should return to the element that opened it, preserving the user's place in the page. The native <dialog> element, opened with showModal(), handles much of this for free, including focus trapping, an inert backdrop, and Escape-to-close, while show() opens the dialog non-modally without trapping focus. Skip links are another essential focus tool: a hidden-until-focused link placed as the first focusable element on each page, usually pointing to a <main> landmark, lets keyboard users jump past repeated navigation directly to the main content.

All chapters
  1. 1Foundations of Web Accessibility
  2. 2The POUR Principles in Practice
  3. 3Semantic HTML and ARIA
  4. 4Keyboard Navigation and Focus Management
  5. 5Visual Accessibility
  6. 6Forms, Images, and Document Structure
  7. 7Dynamic Interfaces and Complex Components
  8. 8Testing, Cognitive Accessibility, and Inclusive Design

Drill it

Reading is not remembering. These come from the Web Accessibility deck:

Q

What is web accessibility?

Web accessibility is the practice of building websites and apps that people with disabilities can perceive, understand, navigate, and use.

Q

Why does accessibility matter?

It improves inclusion, usability, legal compliance, and overall product quality for everyone.

Q

What is WCAG?

WCAG stands for Web Content Accessibility Guidelines, the main standard used to evaluate digital accessibility.

Q

What are the four WCAG principles?

Content should be Perceivable, Operable, Understandable, and Robust.