A website can look complete and still be difficult to use.
Open it without a mouse. Press Tab. Can you see where you are? Does the next press take you somewhere expected? Can you open a menu, close a dialog and return to the task?
Keyboard accessibility is not a feature added to the end of a project. It is part of how the interface moves.
The visual layout, HTML structure, component behavior and focus states all contribute to that movement. A mistake in any one of them can make a polished interface feel broken.
What keyboard accessibility means in practice
Keyboard users need to reach and operate the interactive parts of a page without relying on a pointer.
For many websites, that means:
Tabmoves forward through interactive controls.Shift + Tabmoves backward.Enteractivates links and buttons.Spaceactivates buttons and operates certain controls, such as checkboxes.Escapecloses a modal dialog or dismisses certain open components.- Arrow keys navigate within some composite components, such as a tab list.
The exact keys depend on the control. A dropdown menu, a group of tabs and a text field do not all follow the same interaction pattern.
The goal is not to make every element react to every key. It is to use familiar behavior consistently, so people can predict what happens next.
Start with the page order
Imagine a checkout page with contact details on the left and an order summary on the right. Visually, the contact form comes first. But when someone presses Tab, focus jumps to the order summary, then back to the first field.
The page may still be technically operable, but the movement is harder to follow.
In a typical HTML document, the order of elements in the document determines the default sequential focus order. Visual layouts can rearrange those elements with CSS without changing their underlying order. That can create a mismatch between what people see and where the keyboard takes them.
Review the interface in three forms:
- The visual order on the screen.
- The order of elements in the document.
- The order followed when navigating with the keyboard.
They do not always have to be identical, but they should make sense together.
Be careful with positive tabindex values used to force a custom order. They can move controls ahead of the normal sequence and make future changes harder to maintain. W3C’s ARIA Authoring Practices strongly advise against using positive values to arrange the tab sequence. Fix the document structure where possible.
Make focus visible
Focus is the current point of keyboard interaction. A focus indicator shows which control will respond when the user presses a key.
If a button receives focus but nothing visible changes, the user has to guess where they are.
A focus indicator can be an outline, border or another clear visual treatment. It needs to remain visible while the control has focus and be distinguishable against the surfaces around it.
An illustrative CSS starting point:
:focus-visible {
outline: 3px solid #005fcc;
outline-offset: 3px;
}
This is not a universal accessibility guarantee. The chosen color, thickness and offset still need to be checked against the actual component and background. A focus ring that works on white may disappear against a blue card.
Avoid removing the browser’s default outline unless a visible replacement is provided. WCAG’s Focus Visible criterion requires a mode of operation where keyboard focus is visible. Focus indicators may also be subject to non-text contrast requirements.
A design system should specify focus states for more than the primary button:
- Text links
- Form fields
- Icon buttons
- Menu items
- Cards that contain interactive controls
- Controls on light, dark and colored surfaces
- Components with error or selected states
Focus and selection also need to be distinguishable. A selected tab indicates which panel is active. Focus indicates where the keyboard is currently positioned. Depending on the component’s behavior, those can be different tabs.
Keep the focused control in view
A visible focus ring does not help if the control is hidden behind a sticky header.
This commonly appears in long pages with fixed navigation, cookie banners or sticky action bars. The page scrolls as the user tabs through it, but the newly focused control ends up beneath an overlay.
WCAG 2.2’s Focus Not Obscured (Minimum) criterion requires that a focused component is not entirely hidden by author-created content. Preventing partial obstruction as well is a stronger usability target.
One possible technique is to reserve space for a known sticky header:
html {
scroll-padding-top: 5rem;
}
The value must match the actual layout. A header that changes height across breakpoints, a sticky footer and an on-screen keyboard can each require further consideration. Test the result at different viewport sizes and zoom levels.
Use the right HTML control
A control should start with the element that matches its purpose:
- Use a link to navigate to another location.
- Use a button to perform an action.
- Use a checkbox for an independent on/off choice.
- Use a radio group when one choice is selected from a set.
For example:
<a href="/pricing/">View pricing</a>
<button type="button" id="open-filters">
Open filters
</button>
A clickable <div> can be made to respond to a mouse, but it does not automatically provide the keyboard and semantic behavior of a button. Recreating that behavior means accounting for focus, activation keys, disabled states and accessible naming.
Native elements do not solve every design problem, but they give the implementation a reliable starting point.
Do not choose an element only because it looks easy to style. Its behavior is part of the design.
Design the path into and out of a modal
A modal dialog temporarily places a task above the rest of the page. If it opens visually but keyboard focus stays behind it, the interface has split into two different experiences.
Define the complete interaction:
- A user activates the control that opens the dialog.
- Focus moves into the dialog.
- Keyboard interaction stays within the modal task while it is open.
- The user can close it with an available control and, where appropriate,
Escape. - After closing, focus returns to the control that opened it, or to another logical place if that control no longer exists.
The initial focus target depends on the content. For a short confirmation, a relevant button may be appropriate. For a long dialog, focusing a heading or introductory text can make the context easier to understand before the user reaches the actions.
The native HTML <dialog> element, when opened as a modal with showModal(), provides browser-managed behavior for several parts of this interaction, including moving focus into the dialog, making outside content inert and supporting Escape. It still needs an accessible name, suitable content and testing in the supported environment.
For a destructive action, do not automatically place initial focus on “Delete” just to reduce one keystroke. Consider the consequences of an accidental activation and the information the user needs before deciding.
Plan what happens when an item disappears
Focus can be lost when the element holding it is removed from the page.
Consider a list of saved addresses. A user focuses “Delete” on the second address and confirms. The address disappears, including the button that held focus.
Where does the user go next?
Possible answers include:
- The next address in the list.
- The previous address if the deleted item was last.
- A heading or “Add address” button if the list is now empty.
The right answer depends on the task and the layout. The important part is that it is intentional.
W3C’s keyboard interface guidance calls out this type of dynamic change: when the active element is removed, developers need to manage focus so that the user retains a logical point of interaction.
The same issue appears when:
- A filter removes the currently focused result.
- An inline editor closes after saving.
- A row is archived.
- A mobile navigation panel closes.
- A dialog’s original trigger disappears after an action.
Record the expected destination in the component specification. “The item disappears” describes the visual result, but it does not describe the user’s next position.
Do not make every control a separate tab stop by default
Simple pages often work well when each interactive control is reached with Tab. More complex widgets may use a different pattern.
A tab list, for example, can be treated as one stop in the page’s tab sequence. Once inside it, arrow keys move between tabs. Depending on the implementation, moving focus may activate a tab immediately, or the user may activate it with Enter or Space.
That choice affects performance and usability. If every arrow press starts a slow network request, automatic activation can make it difficult to browse the tab labels. W3C’s guidance recommends considering latency when deciding whether selection should follow focus.
Do not add arrow-key navigation to unrelated controls just because a component looks like a row. Use an established interaction pattern when the interface actually behaves like that component.
A row of navigation links and a tab list may look similar, but they have different purposes and expected behavior.
Include keyboard behavior in the design handoff
A component library often documents color, spacing, typography and hover states. Keyboard behavior deserves the same level of attention.
For each interactive component, record:
| Decision | Example |
|---|---|
| Purpose | Opens a filter panel |
| Control | Button with a clear accessible name |
| Focus state | Visible against the header and panel |
| Activation | Enter or Space |
| On open | Focus moves according to the panel’s interaction pattern |
| On close | Focus returns to the trigger when it remains available |
| Dynamic changes | Define a logical destination if the focused item disappears |
| Responsive behavior | Focused controls remain visible around sticky content |
The table is a practical handoff template, not a complete accessibility specification. A non-modal filter panel may need different focus behavior from a modal dialog. Name the pattern before deciding how it operates.
Test an actual task without a mouse
A keyboard review should follow a real journey through the product, not just count how many controls can receive focus.
For an online shop, try this:
- Open the site and reach the product list.
- Open and change a filter.
- Move to a product and open its page.
- Choose a variant and add it to the cart.
- Open the cart and remove the item.
- Confirm that focus stays in a meaningful place.
- Continue until reaching checkout.
During the flow, check:
- Can every required action be reached and operated?
- Is the focused control visible at every step?
- Does the order match the task and the visual layout?
- Can menus and dialogs be opened and closed?
- Does focus remain useful after content changes?
- Do sticky elements cover controls?
- Are focus and selected states distinguishable?
Repeat the test at a narrow viewport and with zoom. Include the browser and operating system settings relevant to the product’s users, since keyboard navigation behavior can vary by environment.
A keyboard pass is valuable, but it is not a complete accessibility audit. Screen reader testing, contrast checks and other reviews cover different parts of the experience.
Treat movement as part of the interface
A page is not just a set of screens. It is a sequence of positions and actions.
A useful keyboard path lets someone reach a control, recognize it, operate it and understand where they are afterwards. That path needs to survive menus opening, items disappearing and layouts changing.
When the path is designed alongside the visual interface, keyboard accessibility becomes easier to specify, implement and review.
Conversation
Discussion
Loading comments…