# Keyboard navigation

## What it is

Keyboard navigation lets a person reach and operate an interface with keyboard
input. On a web page, the Tab key commonly moves among focusable elements. Shift
and Tab can move in the reverse direction. Native controls provide expected ways
to activate or adjust them. A link can be opened with the keyboard. A button
accepts the activation behaviour the browser provides for it.

Some components use additional keys within a group. A tab interface or listbox
can have one place in the ordinary Tab sequence and use arrow keys to move among
related items. Its behaviour should follow a recognised pattern and remain
discoverable to the user. When one element receives focus, the interface should
make its location apparent. The person should be able to follow the next action
without relying on pointer hover.

Keyboard access matters for people using a physical keyboard, switch input and
other assistive technologies that operate through keyboard conventions. The
user's task determines the scope. A test should cover reaching the control,
using it, understanding changes and continuing to the next part of the
interface.

## Why it matters

A page can provide everything through pointer interaction while leaving a
keyboard user unable to reach an important action. A user may also reach an
element but find its focus indicator clipped or hidden. Both conditions
influence whether the interface is usable. Check the actual rendered state and
the path a person follows, including controls that start out collapsed.

Order carries meaning. A person can expect to reach a section before its actions
or pass through a group in the sequence shown on screen. A reordered layout can
show one order visually and another in the document's focus sequence. Follow the
task in both directions and compare what a person sees with what the keyboard
reaches. Keep the order predictable as components wrap or their language
changes.

Some failures become visible only once a control is open. A menu might include
items behind a clipped area. A disclosure can open but leave focus on a distant
part of the page. A keyboard-only visit needs a way to enter, use and leave the
opened area. Small states should be tested on their own and also as part of an
actual visit.

## What it looks like in practice

Open a representative page with the pointer out of the way. Start at the top and
press Tab through the first controls. Confirm the location of focus, whether an
active highlight can be seen and which action the browser performs on
activation. Follow a link to another part of the same page and continue. The
next focus point should be easy to understand from the new position.

Exercise a menu or disclosure with the native keyboard commands applicable to
it. Open it, move among the relevant choices and close it using its documented
behaviour. Then continue past it and check reverse navigation. For a composite
control with arrow-key selection, verify both the entry point and how the person
leaves it using Tab. The test should retain the intended semantics of the
underlying widget.

Engineer's [accessibility statement](/accessibility/) describes pressing real
Tab keys through representative pages, checking focus indicators, and using a
first stop that leads directly to the content. It also records what the test
scope covers. The example here builds on that method by checking open and closed
states and the user's continuation after activation. A good release check
observes the interaction at the actual viewport size and language.

Add a narrow layout and a short viewport to the same exercise. A sticky bar can
cover an element the browser scrolls into view. A translated menu can grow
longer than expected. Use a viewport that exposes those interactions and record
which target the user can see when they arrive at it. These conditions make
tests more useful than counting focusable elements in the markup alone.

## Where it goes wrong

A control can be activated by clicking while lacking a working keyboard action.
Start with the appropriate native element and verify the browser's activation.
If a custom widget adds keyboard behaviour, check the role, focus movement and
state changes together. An isolated key event is useful only when the user can
reach the element and understand what happened.

A common failure is a keyboard trap. A person can reach an interactive area and
then lack a usable way to leave it. Follow the complete key sequence after
entering and test the exit path as carefully as the entry path. Modal interfaces
intentionally constrain focus while open and need an available close operation
and a reasonable next location afterward.

Also test the keyboard's interaction with text fields and scrolling areas. Arrow
keys can move a caret, choose a widget option or scroll a region depending on
what has focus. Custom handling should preserve the expected action in each
context. Use a real key sequence that starts outside the component, enters it
through its normal path and continues after the last control. The fixture should
show what a person can do before the component gains focus and after it loses
it.

Finally, preserve keyboard checks when changing the visual design. Scrolling,
animation, responsive layout and fixed elements can alter the result without
changing the links in the document. A reliable fixture presses real keys and
observes the visible location and action. That evidence helps a team understand
which part of an actual task a new layout makes easier or harder.

## Further reading

- [WCAG Keyboard](https://www.w3.org/WAI/WCAG22/Understanding/keyboard.html).
  Explains how functionality should be operable through a keyboard interface.
- [WCAG No Keyboard Trap](https://www.w3.org/WAI/WCAG22/Understanding/no-keyboard-trap.html).
  Discusses entering and leaving interactive areas.
- [WAI keyboard interface practices](https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/).
  Provides keyboard conventions for common widgets.

<https://engineer.company/glossary/keyboard-navigation/>
