Keyboard Accessibility Testing Without a Mouse
In this article
Keyboard accessibility testing ensures that every interactive element on a webpage can be reached and operated using only the keyboard. This is essential for people with motor disabilities, power users, and it's a core requirement of WCAG (Web Content Accessibility Guidelines). This guide walks you through a practical, step-by-step method to test your site's keyboard accessibility without touching a mouse.
What You'll Need
- A computer with a keyboard (laptop or desktop).
- A web browser (Chrome, Firefox, Safari, or Edge are all fine).
- The webpage you want to test (open in a browser tab).
- Optional: a screen reader (like NVDA on Windows, VoiceOver on Mac) for more advanced checks, but not required for basic testing.
Step-by-Step
- Start at the top of the page. Click on the browser's address bar and press Tab to move focus into the page. Alternatively, press Ctrl+L (or Cmd+L on Mac) to focus the address bar, then press Tab to enter the page content.
- Use Tab to move forward. Press Tab repeatedly to cycle through all interactive elements: links, buttons, form fields, and menus. Watch the focus indicator (usually a visible outline or highlight) as it moves. It should move in a logical order – typically top to bottom, left to right.
- Use Shift+Tab to move backward. Press Shift+Tab to go in reverse. This checks that you can navigate back through the page without getting stuck.
- Activate elements with Enter and Space. When focus is on a link or button, press Enter to activate it. For buttons (and sometimes links), Space also works. Test both to ensure they respond as expected.
- Test form fields. When focus is on a text input, type text. For checkboxes, press Space to toggle. For radio buttons, use arrow keys to select an option. For dropdowns (select elements), use arrow keys to change options and Enter to confirm.
- Test custom widgets. If the page has sliders, date pickers, or tabs, use arrow keys, Home, End, and Page Up/Page Down as appropriate. For example, a slider typically responds to left/right arrows, while tabs often use arrow keys to switch between them.
- Check for a visible focus indicator. As you tab, the focused element should be clearly highlighted. If you can't tell where you are, that's a problem. The indicator should have sufficient contrast against the background.
- Test for keyboard traps. If you tab into an element (like a modal dialog or a complex widget) and can't tab out using Tab or Shift+Tab, that's a keyboard trap. Press Esc to see if it closes, and check if you can reach the close button.
- Test the Escape key. Press Esc to close popups, modals, or dropdown menus. It should work consistently.
- Test page scrolling. Use arrow keys, Space, Page Up, Page Down, Home, and End to scroll the page. This is especially important for content that overflows the viewport.
- Test the browser's built-in features. Use Ctrl+F (or Cmd+F) to find text, Ctrl+P to print, and F5 to refresh. These should work normally.
- Document issues. As you test, note any elements that are unreachable, don't show focus, or behave incorrectly. Record the URL, the element, and the exact keystrokes that caused the problem.
Common Mistakes
- Assuming Tab order is the same as visual order. The tab order is determined by the DOM order, not CSS positioning. A visually rearranged layout can cause a confusing tab order.
- Not testing with a real keyboard. Some browser dev tools simulate keyboard events, but they don't replicate the actual focus behavior. Always test with a physical keyboard.
- Ignoring the focus indicator. A focus indicator that is too subtle (or removed entirely) is a common accessibility failure. Make sure it's clearly visible.
- Forgetting to test custom components. JavaScript-heavy widgets often lack proper keyboard support. Always test them thoroughly.
- Only testing forward navigation. Always test backward navigation with Shift+Tab as well.
Tips
- Use a browser extension. Tools like Accessibility Insights or axe DevTools can help identify common issues, but they don't replace manual testing.
- Test in multiple browsers. Keyboard behavior can vary slightly between browsers, so test in at least two.
- Turn on high contrast mode. This can help you see the focus indicator more clearly, especially on low-contrast designs.
- Use the keyboard to navigate the browser's own UI. Press F6 to cycle between the address bar, bookmarks, and page content. This helps you understand the overall keyboard flow.
- Practice using the keyboard for everything. The more you use it, the more natural it becomes, and the quicker you'll spot issues.
Troubleshooting
Focus skips elements. If Tab skips a link or button, it likely has tabindex="-1" or is not focusable by default. Check the HTML and remove any negative tabindex unless it's intentional (e.g., for a modal that manages focus itself).
Focus gets stuck. If you can't tab out of an element, it's a keyboard trap. Press Esc to try to close it, then inspect the JavaScript. The trap often occurs in modals or custom widgets that don't handle focus properly. Ensure the modal has a close button that is focusable and that focus returns to the trigger element when closed.
Enter doesn't activate a button. Some browsers only activate buttons with Space, not Enter. If a button doesn't respond to Enter, it might be a <div> with a click handler instead of a real <button>. Use native elements whenever possible.
Arrow keys don't work in dropdowns. If arrow keys don't change options in a <select>, the element might be a custom dropdown built with JavaScript. Custom dropdowns need to implement ARIA patterns (like role="listbox") and handle arrow keys manually.
Focus indicator is invisible. If you can't see where you are, the CSS likely removes the default outline (outline: none). Add a visible focus style, like :focus { outline: 2px solid blue; }.
Page doesn't scroll with arrow keys. This can happen if the page has a fixed height or overflow hidden. Check the CSS for overflow: hidden on the body or a container, and ensure the main content is scrollable.
Frequently Asked Questions
- Q: Do I need a screen reader to test keyboard accessibility?
No, you can test the basic keyboard functionality without one. A screen reader is useful for testing screen reader-specific features, but for pure keyboard navigation, a physical keyboard is enough. - Q: What is the most important keyboard shortcut to test?
The Tab key is the most critical. If you can't navigate through the page with Tab, the rest doesn't matter. Also test Shift+Tab for backward navigation. - Q: How do I test a custom dropdown menu?
Focus the dropdown trigger, then press Enter or Space to open it. Use arrow keys to move through options, and Enter to select. Press Esc to close. Ensure the focus doesn't get trapped inside. - Q: What does 'focus trap' mean?
A focus trap occurs when a user can't move focus away from an element using the keyboard. It's a common issue with modals and dialogs. To test, press Tab repeatedly – if you never leave the modal, it's trapped. - Q: Can I test keyboard accessibility on a mobile device?
Mobile devices typically don't have a physical keyboard, but you can connect a Bluetooth keyboard to test. However, the primary concern for mobile is touch accessibility, which is a separate test. - Q: What if the page has a skip link?
Skip links are great – they let keyboard users jump to the main content. When you press Tab on the page, the skip link should appear first. Activate it with Enter to jump to the content. Test that it works.