Sub topic 6
Designing for keyboard use
This chapter assumes you know the basics of wireframing and common UI components such as forms, menus and buttons. It also assumes you have read the earlier chapters on page structure and on reading and focus order. Here you will specify how each interactive element behaves when someone uses only a keyboard.
Why keyboard use is a design decision
Many people never touch a mouse. Screen reader users, people with motor impairments, people who use switch devices or voice control, and power users all depend on keyboard-style input. Their tools usually send the same events as a keyboard, so a design that works by keyboard tends to work for them too.
WCAG (the Web Content Accessibility Guidelines) covers this under the Operable principle. Four success criteria matter most at wireframe time:
- 2.1.1 Keyboard (Level A): all functionality works from a keyboard.
- 2.1.2 No Keyboard Trap (Level A): focus can always move away from a component using standard keys.
- 2.4.3 Focus Order (Level A): focus moves in a sequence that preserves meaning.
- 3.2.1 On Focus (Level A): moving focus to an element does not trigger an unexpected change of context.
Developers can fix many bugs late. Keyboard problems are different, because they often come from the design itself. A hover-only menu, a drag-only list or a custom widget with no defined keys cannot be repaired by adding a tab stop. The wireframe has to describe the interaction.
The keys you can rely on
Browsers give users a standard set of keys. Design around them instead of inventing new ones.
| Key | Expected behavior |
|---|---|
| Tab | Move focus to the next focusable element |
| Shift+Tab | Move focus to the previous focusable element |
| Enter | Activate links and buttons, submit forms |
| Space | Activate buttons, toggle checkboxes, scroll the page |
| Arrow keys | Move within a group such as radio buttons, tabs, menus or a listbox |
| Escape | Close or cancel a dialog, menu or popup |
| Home / End | Jump to the first or last item in a list or menu |
A useful rule: Tab moves between components, arrow keys move within a component. A set of radio buttons is one Tab stop. A tab list is one Tab stop. Without this rule, a toolbar with 20 buttons forces 20 presses of Tab to cross.
Which elements are focusable
Native links, buttons, form fields and a few other elements are focusable by default. Plain text, images and layout containers are not, and they should not be. Adding every paragraph to the Tab sequence slows people down and adds nothing.
When you review a wireframe, mark each element in one of three ways:
- Interactive: it must be reachable and operable by keyboard.
- Informational: it is read as content but is not a Tab stop.
- Decorative: it is skipped entirely.
Anything you drew with a click, hover, drag or swipe gesture belongs in the first group, so it needs a keyboard equivalent.
Common patterns and the keys to specify
Skip link
Long headers and navigation bars make keyboard users press Tab many times before reaching the content. Specify a "Skip to main content" link as the first focusable element. It can stay hidden until it receives focus, but your wireframe should show where it appears and where it jumps to.
Menus and disclosure navigation
Hover menus are the most common keyboard failure in designs. For site navigation, a disclosure pattern is usually the safest choice: a button toggles a list of links. Specify it like this:
- Enter or Space on the button opens the list.
- Tab moves through the links in the list.
- Escape closes the list and returns focus to the button.
Avoid the ARIA menu role for ordinary site navigation. It promises application-style arrow-key behavior that you would then have to build and test in full.
Tabs
A tab list is one Tab stop. Left and Right arrows move between tabs, and Home and End jump to the first and last. The panel below it is the next Tab stop. Decide whether arrow keys activate a tab immediately or only move focus to it. Immediate activation suits content that loads instantly. Manual activation, with Enter or Space, suits panels that are slow to load.
Dialogs
A modal dialog needs four behaviors, and you can draw all four in the wireframe:
- Focus moves into the dialog when it opens, usually to the first field or the dialog heading.
- Tab and Shift+Tab stay inside the dialog while it is open.
- Escape closes it.
- Focus returns to the element that opened it.
Note the difference from a keyboard trap. A trap leaves a user stuck. A modal dialog keeps focus inside on purpose, and it always offers a way out through Escape and a visible close button.
Custom widgets and drag and drop
Anything that relies on dragging needs a single-pointer or keyboard alternative. WCAG 2.2 adds criterion 2.5.7 Dragging Movements (Level AA) for this. A sortable list, for example, can offer "Move up" and "Move down" buttons on each row. Sliders can accept arrow keys and optionally a number field. Draw these alternatives in the wireframe so they are not forgotten.
Single-character shortcuts
If you plan shortcuts such as pressing "G" to go to the inbox, criterion 2.1.4 Character Key Shortcuts (Level A) requires a way to turn them off, remap them, or make them active only when the relevant component has focus. Voice control users can trigger stray shortcuts by accident while dictating, so this rule has real effects.
Expressing the order
Focus order usually follows the visual and reading order. Chapter-level reminders:
- Focus order follows the DOM (the order of elements in the HTML), not the visual position. A layout that looks right on screen can still tab in a confusing order.
- Avoid positive
tabindexvalues such astabindex="5". They override the natural order and are difficult to maintain. - Use
tabindex="0"only for custom interactive elements that must join the sequence. Usetabindex="-1"for elements that should receive focus from script, such as a dialog heading, but not from Tab.
On a wireframe, number the Tab stops with small circles. Keep the numbers in sequence, and mark groups that behave as one stop with a bracket.
Managing focus when the page changes
Static pages are easy. Problems appear when content changes without a page load. Specify where focus goes in each case:
| Event | Focus should go to |
|---|---|
| Dialog opens | Inside the dialog |
| Dialog closes | The control that opened it |
| Item is deleted from a list | The next item, or the list heading if none remain |
| Form submission fails | The error summary or the first invalid field |
| Single-page app changes route | The new page's `h1` or main region |
| Inline content expands | Stays on the control that expanded it |
If focus stays on an element that disappears, it drops back to the top of the page, and the user loses their place.
A small worked example
Here is a disclosure button and a list of links, with the keyboard behavior described above. The code is complete and runs in a browser as a single file.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Disclosure navigation</title>
<style>
:focus-visible { outline: 3px solid #005fcc; outline-offset: 2px; }
#products-list[hidden] { display: none; }
</style>
</head>
<body>
<a href="#main">Skip to main content</a>
<nav aria-label="Main">
<button type="button" id="products-btn"
aria-expanded="false" aria-controls="products-list">
Products
</button>
<ul id="products-list" hidden>
<li><a href="/laptops">Laptops</a></li>
<li><a href="/phones">Phones</a></li>
</ul>
</nav>
<main id="main" tabindex="-1">
<h1>Welcome</h1>
</main>
<script>
const btn = document.getElementById("products-btn");
const list = document.getElementById("products-list");
function setOpen(open) {
btn.setAttribute("aria-expanded", String(open));
list.hidden = !open;
}
btn.addEventListener("click", () => {
setOpen(btn.getAttribute("aria-expanded") !== "true");
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape" && !list.hidden) {
setOpen(false);
btn.focus();
}
});
</script>
</body>
</html>The native button gives you Enter and Space support without extra code. The script only adds what the browser does not provide: Escape handling and focus return.
How the interaction flows
Common errors
- Hover-only content. Tooltips and menus that appear only on hover are unreachable by keyboard. Provide a focus trigger as well, and keep the content visible until the user dismisses it.
- Clickable divs. A
divwith a click handler is not focusable and does not respond to Enter or Space. Specify a real button or link in the annotation. - Removed focus outlines. Setting
outline: nonewith no replacement hides where the user is. The next chapters cover focus visibility in detail. - Hidden but focusable items. Off-screen menus that remain in the Tab order make focus vanish. Hidden content should be removed from the order with the
hiddenattribute ordisplay: none. - Focus changing on focus. Auto-submitting a form or opening a new window when an element receives focus breaks criterion 3.2.1.
- Unexpected traps. Embedded widgets such as maps or rich text editors may capture Tab. Specify an exit key and mention it in the annotation.
Annotation checklist
For each interactive element on a wireframe, record:
- Its Tab stop number, or the group it belongs to.
- The keys that operate it.
- Where focus goes after it is activated.
- What happens on Escape, if it opens something.
Exercise
A wireframe shows a product card grid. Each card has an image, a title, a price and an "Add to cart" button. The title is also a link to the product page, and the image is a second link to the same page. Specify the Tab stops for one card and say why.
Show answer
Use three focusable items at most, and preferably two: the title link and the "Add to cart" button. Make the image link redundant by removing it from the Tab order with tabindex="-1" and an empty alt, or wrap the whole card content in one link. This avoids two adjacent links to the same destination, which add a stop and a duplicate announcement for screen reader users. The order is title link, then "Add to cart", matching the reading order. The button label should name the product, for example "Add to cart, Blue kettle", so the purpose is clear out of context.
Exercise
A modal dialog for deleting an account has a "Cancel" button, a "Delete" button and a close icon. List the keyboard behaviors you would annotate on the wireframe.
Show answer
On open, move focus into the dialog, ideally to the dialog heading or to "Cancel", the safer action for a destructive dialog. Tab and Shift+Tab cycle only among the close icon, "Cancel" and "Delete" while the dialog is open. Escape closes the dialog without deleting. On close, return focus to the control that opened it. The background content should be inert, so it is neither focusable nor read by screen readers while the dialog is open.