Keyboard Navigation Accessibility: A Complete WCAG Guide
Millions of people navigate the web without a mouse. Learn how to build keyboard-accessible websites with proper focus management, tab order, skip links, and visible focus indicators.
Not everyone uses a mouse
It's easy to assume that everyone navigates the web the way you do - clicking with a mouse or tapping on a touchscreen. But millions of people rely on a keyboard as their primary or only means of interaction.
People with motor disabilities may use a keyboard, a switch device, or voice recognition software - all of which interact with web pages through the same keyboard interface. Screen reader users navigate almost entirely by keyboard. Power users often prefer keyboard shortcuts for speed. And anyone with a temporarily broken mouse or trackpad needs keyboard access as a fallback.
Keyboard accessibility isn't an edge case. It's the foundation that makes all other assistive technologies work. If your site isn't keyboard accessible, it's likely inaccessible to screen readers, voice control, and switch devices as well.
How keyboard navigation works
Understanding the basics of keyboard navigation helps you test and build accessible interfaces.
The essential keys
- Tab - moves focus to the next interactive element (links, buttons, form fields)
- Shift + Tab - moves focus to the previous interactive element
- Enter - activates the focused element (follows links, submits buttons)
- Space - activates buttons, toggles checkboxes, opens select menus
- Arrow keys - navigate within components (radio groups, dropdown menus, tabs, sliders)
- Escape - closes modal dialogs, menus, and popups
With just these keys, a user should be able to reach and operate every interactive element on your page. If they can't, you have a keyboard accessibility problem.
Focus order
When a user presses Tab, focus moves through interactive elements in DOM order - the order elements appear in your HTML source code. This is why it's important that your visual layout matches your source order. If CSS visually rearranges elements (using flexbox order, grid placement, or absolute positioning), the tab order might not match what a sighted user expects.
You can verify focus order by pressing Tab through your page and checking that focus moves in a logical sequence - generally left to right, top to bottom, matching the visual flow of content.
Focus indicators - making focus visible
When a keyboard user tabs through a page, they need to see which element currently has focus. This visual indicator is called the focus ring or focus indicator.
Browsers provide a default focus indicator (usually a blue or dotted outline), but many websites remove it with CSS like outline: none or *:focus { outline: 0; } because designers find it aesthetically displeasing. This is one of the most harmful accessibility patterns on the web - it makes keyboard navigation essentially unusable.
Best practices for focus indicators
- Never remove focus indicators without providing a replacement. If you remove the default outline, you must add a custom one that's equally visible.
- Make focus indicators visible against all backgrounds. A thin blue outline works on white but may be invisible on a blue background. Use a combination of outline offset, contrasting colors, or multiple indicators.
-
Use
:focus-visiblefor the best of both worlds. The:focus-visiblepseudo-class only applies focus styles when focus was triggered by keyboard (not mouse click), reducing visual noise for mouse users while keeping indicators for keyboard users.
A good custom focus indicator might look like this:
:focus-visible { outline: 3px solid #1a73e8; outline-offset: 2px; }
WCAG 2.2 added specific requirements for focus appearance (criterion 2.4.13, Level AA): focus indicators must have a minimum area and contrast ratio. This means the days of barely-visible dotted outlines are numbered.
Skip links - bypassing repeated content
Imagine having to Tab through an entire navigation menu with 30 links on every single page before reaching the main content. For keyboard users, this is exhausting and time-consuming.
Skip links solve this by providing a link at the very top of the page that jumps directly to the main content area. It's typically hidden until it receives focus, so it doesn't affect the visual design:
<a href="#main-content" class="skip-link">Skip to main content</a>
The CSS hides it visually until focused:
.skip-link { position: absolute; top: -40px; left: 0; } .skip-link:focus { top: 0; }
This is a WCAG Level A requirement (2.4.1 Bypass Blocks) and takes minimal effort to implement. Many users who benefit from skip links consider them one of the most impactful accessibility features a site can offer.
Keyboard traps - the cardinal sin
A keyboard trap occurs when a user can Tab into an element but cannot Tab out of it. They're stuck, unable to navigate to other parts of the page without using a mouse - which they may not be able to do.
Common sources of keyboard traps include:
- Embedded content - iframes, embedded maps, and third-party widgets can trap focus inside their boundaries
- Custom rich text editors - editors that capture Tab for indentation can prevent users from tabbing away
- Modal dialogs without proper focus management - a modal should trap focus within itself while open (this is correct behavior) but must release focus when closed
- Autofocusing scripts - JavaScript that forces focus back to a specific element whenever the user tries to leave
Test for keyboard traps by tabbing through your entire page. If you ever get stuck and can't move forward with Tab or backward with Shift+Tab, you've found a trap. WCAG criterion 2.1.2 (No Keyboard Trap, Level A) explicitly prohibits this.
Making custom components keyboard accessible
Native HTML elements like <button>, <a>, and <input> are keyboard accessible by default - they receive focus, respond to Enter/Space, and announce themselves to screen readers. Problems arise when developers build custom interactive elements from non-interactive HTML.
A clickable <div> with a JavaScript click handler is invisible to keyboard users - it doesn't appear in the tab order, and pressing Enter does nothing. To make it accessible, you'd need to add:
-
tabindex="0"- puts the element in the natural tab order -
role="button"- tells assistive technologies it's a button - A keydown handler for Enter and Space
- Proper focus styles
Or you could just use a <button> element and get all of this for free. The simplest rule for keyboard accessibility: use native HTML elements whenever possible. A <button> instead of a <div onclick>. An <a href> instead of a <span onclick>. Native elements handle keyboard interaction, focus management, and screen reader announcements automatically.
Testing keyboard accessibility
The best way to test keyboard accessibility is to actually use your keyboard. Put your mouse aside and try to complete every task on your site using only these keys: Tab, Shift+Tab, Enter, Space, Arrow keys, and Escape.
As you navigate, check for these common issues:
- Can you see where focus is? If you lose track of the focused element, your focus indicators need improvement.
- Does the tab order make sense? Focus should move logically through the page, matching the visual layout.
- Can you reach every interactive element? Buttons, links, form fields, menus, and custom widgets should all be focusable.
- Can you activate every control? Links should work with Enter, buttons with Enter or Space, checkboxes with Space.
- Can you always escape? You should never get trapped. Modals should close with Escape. Menus should close with Escape.
- Is there a skip link? Tab once from the top of the page - a "Skip to main content" link should appear.
How AccessGuard helps with keyboard accessibility
AccessGuard's keyboard checker identifies elements that may cause keyboard accessibility issues - missing focus indicators, elements with click handlers but no keyboard handlers, tab order anomalies, and missing skip links. While automated testing can't catch every keyboard issue (some require manual verification), it provides a reliable starting point that highlights the most common problems.
Combined with the manual testing checklist above, you can systematically verify and improve keyboard accessibility across your entire site.