Keyboard Accessibility
The experts at WebAIM can audit your web site and provide a detailed report to help you remediate accessibility and WCAG compliance issues.
Introduction
Ensure that all content can be accessed with the keyboard alone.
Keyboard accessibility is one of the most important aspects of web accessibility. Many users with motor disabilities rely on a keyboard. Some people have tremors which don't allow for fine muscle control. Others have little or no use of their hands, or no hands at all. In addition to traditional keyboards, some users may use modified keyboards or other hardware that mimics the functionality of a keyboard. Blind users also typically use a keyboard for navigation. Users without disabilities may use a keyboard for navigation because of preference or efficiency.
Potential Problems
There are many ways that a webpage can introduce difficulties for users who rely on a keyboard for navigation. Below are a few of the most common issues.
Focus indicators
A keyboard user typically uses the Tab key to navigate through interactive elements on a web page—links, buttons, fields for inputting text, etc. When an item is tabbed to, it has keyboard "focus" and can be activated or manipulated with the keyboard. A sighted keyboard user must be provided with a visual indicator of the element that currently has keyboard focus. Focus indicators are provided automatically by web browsers. While their appearance varies based on the browser, the focus indicator is typically shown as a border or highlight (called an outline) around the focused element. These outlines can be hidden by applying outline:0
or outline:none
CSS to focusable elements.
Avoid outline:0
or outline:none
or other styles that remove or limit visibility of keyboard focus indicators.
In addition to the default outline, you can use CSS to make the focus indicator more visually apparent and keyboard-friendly by ensuring the focus indicator is highly visible with sufficient contrast, and by adding a background color or other visual focus style to links and other interactive controls. The outline can be styled to match your site design but should be readily detected when navigating with the Tab key.
Items that should not receive keyboard focus
Links, buttons, and form controls are natively accessible to keyboard users, so should be used for interactivity whenever possible. Page elements that are not interactive to mouse or touch users should not be made keyboard focusable (such as by using tabindex
). Making non-interactive elements keyboard navigable will cause confusion.
Note: An <a>
element is only keyboard accessible or presented to screen reader users as a link when it has a non-empty href
attribute. <a>
(without an href
attribute) or <a href="">
(no href
attribute value) should not be used for links.
Inaccessible custom widgets
If a native HTML element is not sufficient, then a custom-made control or widget might be necessary. All custom controls must still be accessible to keyboard users. You may need to use tabindex="0"
to ensure an element can receive keyboard focus. ARIA may also be necessary to ensure that the control or widget is presented correctly to screen reader users. The ARIA Authoring Practices outlines necessary keyboard interactions and ARIA coding necessary for many types of custom widgets. To be made highly accessible the following must occur:
- The interaction is presented in an intuitive and predictable way
- JavaScript event handlers work with a keyboard and a mouse.
- The interaction uses standardized keystrokes.
Lengthy navigation
Sighted mouse users are able to visually scan a web page and directly click on any item. Keyboard users must press the Tab key or other navigation keys to navigate through the interactive elements that precede the item the user wants to activate. Tabbing through lengthy navigation may be particularly demanding for users with motor disabilities.
Long lists of links or other navigable items may pose a burden for keyboard-only users. The following best practices can facilitate efficient keyboard navigation:
- Provide a "skip to main content" link on the page.
- Use a proper heading structure.
- Provide regions or ARIA landmarks (
<main>
,<nav>
, etc.)
Keyboard Testing
Testing with a keyboard is an essential part of any accessibility evaluation.
The following table includes many of the most common online interactions, the standard keystrokes for the interaction, and additional information on things to consider during testing.
Interaction | Keystrokes | Notes |
---|---|---|
Navigate to interactive elements |
|
|
Link |
|
|
Button |
|
Ensure elements with ARIA role="button" can be activated with both key commands. |
Checkbox |
|
Users can typically select zero, one, or multiple options from group of checkboxes. |
Radio buttons |
|
Users can select only one option from a group of radio buttons. |
Select (dropdown) menu |
|
You can also filter or jump to options in the menu as you type letters. |
Autocomplete |
|
|
Dialog |
|
|
Slider |
|
|
Menu bar |
|
|
Tab panel |
|
|
'Tree' menu |
|
|
Scroll |
|
The space bar will, by default, scroll the page, but only if an interactive control that allows space bar input is not focused. Horizontal scrolling within the page should be minimized. |
The ARIA authoring practices document provides additional information for these and other common interactions. Be sure to test keyboard accessibility on mobile devices—users with disabilities often utilize an external keyboard with phones and tablets.