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. Blind users also typically use a keyboard for navigation. Some people have tremors which don't allow for fine muscle control. Others have little or no use of their hands. Some people simply do not have hands, whether due to a birth defect, an accident, or amputation. In addition to traditional keyboards, some users may use modified keyboards or other hardware that mimics the functionality of a keyboard.
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.
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 has keyboard "focus", it 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. A basic focus indicator is provided automatically by the web browser and is typically shown as a border (called an outline) around the focused element. However, these outlines can be hidden by applying
outline:none CSS to focusable elements.
outline:0 or similar styles on links and other elements that can receive keyboard focus.
In addition to the default outline, you can use CSS to make the focus indicator more visually apparent and keyboard-friendly by adding a background color or other visual style to links, and other controls that will receive keyboard focus. The outline can be styled to match your site design.
Items that cannot receive keyboard focus
By default, users can only navigate to links, buttons, and form controls with a keyboard. These natively-accessible elements should be used whenever possible. If this is not possible, you may need to use
tabindex="0" to ensure an element can receive keyboard focus.
<a> element is only keyboard accessible or presented to screen reader users as a link when it has a non-empty
<a> (without an
href attribute) or
<a href=""> (no
href attribute value) should not be used for links.
Inaccessible custom widgets
Although elements that are natively keyboard accessible should be used when possible, there are times when HTML falls short and custom "widgets" are necessary. Complex menus, sliders, dialogs, tab panels, etc. must all be built to support keyboard accessibility. This means the following must occur:
- The interaction is presented in an intuitive and predictable way
- The interaction uses standardized keystrokes.
The ARIA design patterns describe standard keyboard interactions for many common widgets.
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:
Testing with a keyboard is an essential part of any accessibility evaluation. The basics of keyboard testing are simple—the Tab key can be used to navigate through links and form controls, Enter (and sometimes Spacebar) selects an element, and the arrow keys are sometimes used for other navigation. However, when testing with a keyboard, you are not just trying to interact with the page successfully, you also want to ensure all interactions are predictable. This requires an understanding of common keyboard interactions.
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.
|Navigate to most elements||
|Button||Enter or Spacebar||Ensure elements with ARIA
|Checkbox||Spacebar - check/uncheck a checkbox||Checkboxes should be used when one or more option can be selected.|
||Radio buttons should be used when only one option from a group can be selected.|
|Select (dropdown) menu||
||You can also filter by typing letters, but this behavior varies by browser. Some will filter as you type, like autocomplete. Others will only sort by first letter. E.g., in a list of US States, hitting A then R may take you to Arizona, or it may take you to Alabama and then Rhode Island.|
|Dialog||Esc - close||
Minimize horizontal scrolling.
The ARIA authoring practices document provides additional information for these and other common interactions.