Keyboard Accessibility Assessment with WCAG
In this article
This guide shows you how to systematically evaluate whether your website or web application can be fully operated using only a keyboard, following the Web Content Accessibility Guidelines (WCAG) 2.1 and 2.2. Keyboard accessibility is a core requirement for users with motor disabilities, and it also benefits power users and improves overall usability. By the end, you'll have a repeatable testing process that aligns with WCAG success criteria.
What You'll Need
- A computer with a standard keyboard (laptop keyboards work fine).
- A modern web browser (Chrome, Firefox, Safari, or Edge).
- Access to the page or application you want to test.
- Optional: a screen reader (like NVDA or VoiceOver) for deeper testing, but not required for basic keyboard checks.
- Optional: browser developer tools (F12) to inspect focus styles and DOM order.
Step-by-Step
- Start at the top of the page. Press Tab to move focus forward. Continue pressing Tab to cycle through all interactive elements. Note the order in which focus moves. It should follow the visual and logical reading order of the page. If focus jumps around unpredictably, that's a failure of WCAG 2.4.3 (Focus Order).
- Check that every interactive element is reachable. Interactive elements include links, buttons, form fields, dropdowns, checkboxes, radio buttons, and custom widgets (like sliders or tabs). If you can't tab to something that looks clickable, it's not keyboard accessible. This violates WCAG 2.1.1 (Keyboard).
- Test all actions with the keyboard. For each interactive element, try to activate it using the appropriate key: Enter or Space for buttons and links, arrow keys for radio buttons, dropdowns, and sliders, and Tab to move between fields. If an action only works with a mouse (like a hover-only menu), that's a failure of WCAG 2.1.1.
- Verify that focus is visible. As you tab through, you should see a clear visual indicator (usually a border, outline, or highlight) on the focused element. If the focus indicator is missing or too faint, it fails WCAG 2.4.7 (Focus Visible). In WCAG 2.2, the indicator must have sufficient contrast and size (1.4.11 Non-text Contrast).
- Test for keyboard traps. While tabbing, try to move focus away from each element. If you get stuck—for example, you can tab into a modal dialog but can't tab out of it—that's a keyboard trap, violating WCAG 2.1.2 (No Keyboard Trap). Ensure you can always leave a component with Tab or Esc.
- Check for skip links. On pages with a lot of navigation or repeated content, press Tab immediately after the page loads. There should be a "Skip to main content" link that appears on focus. This helps keyboard users bypass long menus, and is part of WCAG 2.4.1 (Bypass Blocks).
- Test custom widgets with arrow keys. For complex components like tabs, accordions, or carousels, the keyboard interaction should follow the WAI-ARIA Authoring Practices. Typically, only one element in a group is in the tab order, and arrow keys move between the others. If arrow keys don't work, or if you have to tab through every item, that's a failure of WCAG 4.1.2 (Name, Role, Value) and 2.1.1.
- Verify that form fields have labels. When you tab into a text input, the label should be announced by a screen reader (or at least be programmatically associated). For keyboard-only testing, you can visually check that each field has a visible label. Missing labels fail WCAG 3.3.2 (Labels or Instructions) and 4.1.2.
- Test with the browser's default focus styles. Many sites remove the outline (using
outline: none) and replace it with nothing. If you see no focus indicator at all, that's a clear failure. If you see a custom style, make sure it's not too subtle. - Repeat the process on different pages. Keyboard accessibility issues often vary by page. Test at least the main navigation, a content page, a form page, and any page with a modal or dialog.
- Document your findings. For each issue, note the URL, the element, the key that failed, and the WCAG criterion it violates. This will help developers fix the issues.
Common Mistakes
- Assuming Tab works everywhere. Tab only moves between focusable elements. Custom widgets (like dropdown menus) need arrow key support. If you only press Tab, you'll miss failures.
- Ignoring the focus order. Even if everything is reachable, if the order is wrong (e.g., focus goes to a footer link before a main content link), it's still a failure.
- Testing only with a mouse. You must physically unplug or ignore the mouse. If you can't perform an action without it, that's a failure.
- Overlooking the focus indicator. A focus indicator that's only a slight color change is not enough. It must be visible against the background.
- Forgetting about modals and dialogs. These are common places for keyboard traps. Always test opening, interacting, and closing a modal.
- Not checking for skip links. Many sites omit them, but they are a WCAG requirement for pages with repeated navigation.
Tips
- Use the browser's built-in tab order. Press Tab and watch the address bar, then the page. This gives you a natural starting point.
- Turn on high contrast mode (Windows: Shift+Alt+PrtScn) to make focus indicators more obvious.
- Use a keyboard-only bookmarklet like "Accessibility Insights" to automate some checks, but manual testing is still essential.
- Check the DOM order. In developer tools, the order of elements in the HTML often matches the focus order. If they differ, that's a red flag.
- Test with a screen reader too. While not strictly keyboard accessibility, screen readers rely on keyboard input, and they can reveal missing labels or roles.
- Keep a checklist. Print out the WCAG keyboard-related criteria and tick them off as you test.
Troubleshooting
- You can't tab to an element at all. This usually means the element lacks a
tabindex="0"(for custom widgets) or is not a native focusable element (like adivwith a click handler). The fix is to addtabindex="0"and implement keyboard event handlers. - Focus gets stuck inside a modal. This is a classic keyboard trap. The modal needs a focus trap that cycles focus within it, but also allows closing with Esc. You may need to add a keydown listener for Tab and Shift+Tab to keep focus inside.
- Arrow keys don't work in a dropdown. The custom widget likely lacks ARIA roles and keyboard handlers. Refer to the WAI-ARIA Authoring Practices for the correct pattern (e.g.,
role="listbox"and arrow key navigation). - Focus indicator disappears on some elements. This often happens when CSS applies
outline: noneglobally. The fix is to add a visible focus style, like:focus-visible { outline: 2px solid blue; }. - Tab order is chaotic. This can be caused by positive
tabindexvalues (e.g.,tabindex="1"). Avoid using positive tabindex; usetabindex="0"for custom elements and rely on DOM order for the rest. - You're not sure if an element is interactive. If it has a click handler, it must be keyboard accessible. If it's a
divorspan, addrole="button"andtabindex="0".
Frequently Asked Questions
Do I need a screen reader to test keyboard accessibility?
No. Basic keyboard testing (tab, enter, space, arrows) can be done without one. A screen reader helps catch missing labels and roles, but the keyboard interaction itself is the same.
What does WCAG 2.1.1 (Keyboard) actually require?
It requires that all functionality be operable through a keyboard interface without requiring specific timings for individual keystrokes. This means you can tab to everything and activate it with standard keys.
Is it okay to use tabindex="-1"?
Yes, tabindex="-1" removes an element from the tab order but still allows it to be focused programmatically (e.g., when opening a modal). It's useful for elements that should not be tabbed to, but can receive focus when needed.
What is a "skip link" and why is it important?
A skip link is a hidden link that appears on focus, usually at the top of the page, that jumps to the main content. It helps keyboard users avoid tabbing through dozens of navigation links. It's required by WCAG 2.4.1.
Can I use JavaScript to make a custom widget keyboard accessible?
Yes, but you must implement the correct keyboard handlers (e.g., arrow keys for tabs, Enter/Space for buttons). Simply adding tabindex is not enough; you need to manage focus and activation.
How do I test for focus order in a single-page app (SPA)?
In SPAs, focus order is often broken when new content loads dynamically. Test by tabbing after each view change. Focus should move to the new content (e.g., an h1 or main container) or at least to the first interactive element.