Keyboard accessibility testing: a step-by-step test with WCAG 2.2

20 min read

  • Testing
  • Keyboard

Keyboard accessibility means you can use every part of a site without a mouse. To test it, put the mouse away. Then move through each page with Tab, Shift+Tab, Enter, Space, the arrow keys and Esc.

Check each thing you can click works by keyboard. Check you never get stuck, and that a skip link takes you past the menus. Check the order makes sense, and that you can always see where you are.

In short

  • Everything must work from the keyboard. That’s WCAG 2.2’s 2.1.1 Keyboard, Level A. Only things like freehand drawing are exempt.
  • You must always see where you are. 2.4.7 Focus Visible (AA) asks for a visible focus indicator. One you style yourself needs 3:1 against the colours next to it.
  • A sticky header mustn’t hide focus. 2.4.11 Focus Not Obscured (Minimum) is AA. Don’t mix it up with 2.4.13 Focus Appearance, which is AAA.
  • A skip link is one way to pass 2.4.1 Bypass Blocks. Landmarks and headings can pass too. GOV.UK requires one on its pages, and the UK’s Department for Work and Pensions (DWP) asks for one on every page.

Put the mouse to one side and use only the keyboard. The keys you need are in the table below. Then run the checks, in order, on each page.

The thing that reacts to your key presses is the one with focus. The mark that shows it, often a ring or outline, is the focus indicator. Most of this test is about where focus goes and whether you can see it.

This page goes deeper than the short keyboard check in how to test website accessibility, which sits in a wider first pass with W3C’s Easy Checks.

Set up your browser

The checks in the Department for Work and Pensions (DWP) Accessibility Manual work in any browser on a PC or a Mac. Its list of keys is for Chrome. In another browser, some keys might be different.

Safari needs setting up first. On its own, Tab in Safari moves only to the next field or pop-up menu. It reaches buttons and other controls only if Keyboard Navigation is on in the Mac’s Keyboard settings.

Option-Tab in Safari also reaches links. To make Tab do that instead, open Safari, then Settings, then Advanced. Turn on “Press Tab to highlight each item on a webpage”. Apple’s Safari keyboard shortcuts page lists both keys.

Some older guides, Easy Checks among them, point to an “All controls” setting in System Preferences instead. Follow Apple’s current pages, since that’s where the setting lives now.

The keys to use

These are DWP’s keys for Chrome, with Apple’s scroll keys for Safari.

The keys to use
Key What it does
Tab Moves forward to the next thing you can use
Shift+Tab Moves back
Enter Opens a link, presses a button or picks an option
Space Presses a button, ticks or clears a checkbox, or opens a drop-down menu
Up and Down arrows Move through radio buttons, menu options and autocomplete options
Esc Closes a dialog box
Space and Shift+Space Scroll the page, unless a form control has focus

In Safari, Space or Page Down moves a screen down the page. Shift-Space or Page Up moves a screen back up. The arrow keys scroll a little at a time.

Inside a group, such as a set of radio buttons, Tab takes you to the group. The arrow keys move between the buttons, and the next Tab leaves the group. That pattern comes from the ARIA Authoring Practices Guide on keyboard use. ARIA stands for Accessible Rich Internet Applications.

The test, step by step

DWP’s manual lists seven keyboard checks, in this order. Each one links to its own section below.

  1. Check that everything you can use with a mouse also works with the keyboard (2.1.1).
  2. Check that you can always move on, and never get stuck (2.1.2).
  3. Refresh the page and press Tab. Check that the first thing you reach is a working skip link (2.4.1).
  4. Tab through the page and check that the order makes sense (2.4.3).
  5. Check that you can always see where focus is (2.4.7).
  6. Open each pop-up and check that focus stays inside it while it’s open (dialogs).
  7. Check that moving focus alone never sends a form or opens a link (3.2.1).

Then add one more check for WCAG 2.2. As you tab, look for focus going behind a sticky header, a cookie banner or a chat window (2.4.11).

Spend the most time on forms, menus and anything with lots of controls. That’s where keyboard problems happen most, W3C says.

How an issue shows up in our reports

Criterion
1.4.3 Contrast (Minimum)
Where
Body text
Status
To fix

Download a sample report →

Keyboard accessible means everything a page does can be done from a keyboard. 2.1.1 Keyboard is Level A. It asks for all functions to work through the keyboard, with no need to press keys at set speeds. The only exception is a task that depends on the path you move along, like freehand drawing.

The exception is about the task, not the way you do it. Handwriting depends on the path. Typing text doesn’t, so text input has to work by keyboard.

A pop-up calendar is a good test. It should also let you type the date.

Who relies on the keyboard

Many people use only the keyboard, or a tool that acts like one. W3C names blind people and some people with mobility impairments. It also names people with low vision, who may find a pointer hard to follow, and some people with hand tremors.

Speech input, sip-and-puff tools, on-screen keyboards and switch devices all work by sending key presses too. People who must avoid the mouse because of repetitive stress injury rely on it too. It helps people with a broken arm, or a broken mouse, too.

What 2.1.1 doesn’t ask for

A mouse emulator such as MouseKeys doesn’t count. It works through the pointer. So a page that needs it fails 2.1.1, unless the exception above applies.

Buttons usually work with both Enter and Space, and that’s the convention to follow. But a custom button that only responds to Enter still meets 2.1.1.

Not every control has to take focus, either. Take a search form whose button can’t get focus. It still passes, because pressing Enter in the text box sends the search.

Native controls come with keyboard support

Real links, buttons and form fields in HTML work with the keyboard by default. Use them where you can. A custom control built from other parts gets no keyboard support from the browser, so someone has to code it.

A keyboard trap is a part of a page you can move into with the keyboard but can’t leave. 2.1.2 No Keyboard Trap is Level A. It says that if focus can move into something, it must be able to move out using only the keyboard. If that takes more than Tab, the arrows or another usual way out, the page must say how.

The usual ways out are Tab and the arrow keys. With a physical keyboard, Esc is a common one too.

Traps often turn up in embedded players and plug-ins, or in custom widgets built without keyboard users in mind. Every part of the page must meet 2.1.2, because one trap can stop someone using the whole page.

Keeping focus inside a modal dialog isn’t a trap, as long as you know how to leave. DWP says the same of a pop-up with a close button. It’s only a trap when there’s no clear way out.

To test it, keep tabbing through every part of the page. Open each pop-up, menu and section that expands, and check you can always move on.

A skip link is a link at the very top of a page that jumps you past the menus to the main content. GOV.UK’s reads “Skip to main content”. Without one, a news page in W3C’s example makes a keyboard user tab through about 40 links to reach the main story. Skip links are one way to meet 2.4.1 Bypass Blocks.

2.4.1 Bypass Blocks is Level A. It asks for a way to skip blocks of content that repeat across pages, such as menus and headers. A single repeated link or word isn’t a block.

The GOV.UK skip link component goes straight after the opening body tag. If the page has a cookie banner, it goes straight after the banner. GOV.UK says not to put it inside a nav region or the header.

Refresh the page and press Tab. The first thing you reach should offer to skip to the main content. Press Enter. Focus should move to the main content.

W3C also has a “Check skip link” bookmarklet on its Easy Checks skip link page. W3C marks that page as a draft. The checker looks only at the first link that jumps down the page.

Some automated tools warn that the skip link isn’t inside a landmark, a named region of the page such as the navigation or the main content. GOV.UK says that warning doesn’t apply to skip links and you can ignore it.

No, not all the time. The Easy Checks draft says it’s best visible as the first link on the page. But hiding it until it gets focus is fine, as long as it’s then easy to see. GOV.UK’s stays hidden until a key press.

So if a team asks how to get rid of “Skip to main content”, the usual answer is to hide it until it’s focused. Keep it on the page.

Other ways to meet 2.4.1

A skip link isn’t the only way to pass. Landmarks and headings at the start of each section. The way past the repeated blocks can even come from the browser or assistive technology.

GOV.UK’s and DWP’s skip link rule is stricter than WCAG. For a UK public sector site, follow it.

Focus order is the order things get focus as you press Tab. 2.4.3 Focus Order is Level A. It asks for an order that keeps the page’s meaning and lets you use it. More than one order can pass. In a table, going row by row or column by column can both be fine.

Without extra code, focus follows the order things appear in the page’s code. DWP’s test is that each Tab press moves to the next thing that makes sense.

One failing example is a form where Tab jumps from the name field to a newsletter checkbox, then back to the address field. Another fail is a button wrapped in a box that also takes focus, so it seems to get focus twice.

Does focus order have to match the visual order?

No. The order doesn’t have to follow the layout, as long as it makes sense and keeps the links between parts. With two separate columns, focusing the right column first isn’t a fail.

It’s still best when the focus order matches the order the layout suggests. DWP says that usually means top to bottom and left to right. Treat that as the normal case, not the rule.

Also, things you can’t click shouldn’t get focus. WCAG advises that but doesn’t require it.

tabindex 0, -1 and positive values

tabindex is the HTML attribute that changes which things get focus. Here’s what each value does, from the ARIA guide.

  • tabindex="0" adds an element to the tab order, at its place in the code.
  • tabindex="-1" keeps it out of the tab order. Script can still move focus to it with element.focus(), which is how you set focus on an element by code.
  • A positive value, from 1 up, jumps the element ahead of everything else. The guide strongly advises against it.

A tabindex order that breaks the page’s meaning is failure F44. The safest way to change the order is to move the elements in the code.

2.4.7 Focus Visible is Level AA. It asks for focus to be visible when you use a keyboard. Once it shows, it must stay. It can’t fade after a few seconds.

A border, an underline, a background colour or a mix of these all work.

Hover isn’t the same as focus. Hovering the mouse over something doesn’t move focus to it, unless a script does that. So a hover style alone doesn’t show keyboard users where they are.

What contrast a focus indicator needs

2.4.7 itself gives no contrast number. The number comes from 1.4.11 Non-text Contrast, which is Level AA.

A focus indicator you’ve styled yourself needs a contrast ratio of at least 3:1 against the colours next to it. If you haven’t changed the browser’s own focus style, it’s exempt from contrast. But it must still be visible.

Take a light grey focus ring on white. It’s 2.3:1, so it fails.

1.4.11 doesn’t directly compare the focused and unfocused looks. That’s the job of 2.4.13, a AAA rule covered below.

The WCAG colour contrast guide on benjaminwalsh.co.uk sets out the three rules that deal with focus side by side.

:focus and :focus-visible

There are two ways to style focus in CSS. :focus works whenever something has focus, even after a mouse click. :focus-visible works only when the browser thinks you need to see focus. Using the keyboard is the main case.

MDN’s page on :focus-visible says it has worked in all main browsers since March 2022. In the past, some sites took the ring away because they found it ugly. MDN says that makes the keyboard hard to use for people who can see. :focus-visible lets you style the ring for keyboard users, and it won’t show on every click.

To make focus visible in CSS, give :focus-visible an outline. Never set the outline to none unless you put something just as easy to see in its place. Styling that hides the focus indicator is failure F78.

MDN’s test is to click each control, then tab through them. With :focus-visible, the ring shows on Tab but not on a click.

2.4.11 Focus Not Obscured (Minimum) is Level AA and is new in WCAG 2.2. It says that when something gets focus, content the site added mustn’t hide it completely.

As you tab, sticky headers, sticky footers and pop-ups that don’t block the page can cover the item with focus. A cookie banner fails if it covers the focused item completely. Partly covered passes at AA, but the less is hidden, the better.

There are three ways to pass with a banner. Make it a modal that must be closed first. Use scroll padding so it doesn’t sit over the content. Or, if it needs no action, close it when it loses focus.

The CSS fix is scroll-padding, which is technique C43. A sticky header or footer that fully hides focus is failure F110.

A chat window you open yourself can fail too, if it stays open over the page. But a menu you open doesn’t count, since it closes when focus moves.

The checklist for product designers on benjaminwalsh.co.uk puts it as one design step: design a visible focus state for every control, and keep it in view under sticky headers and banners.

At AAA, 2.4.12 Focus Not Obscured (Enhanced) goes further. No part of the focused item may be hidden.

2.4.13 Focus Appearance is Level AAA. A WCAG 2.2 AA test doesn’t include it, since it’s AAA. It sets how big and how strong a focus indicator must be.

It has two parts. The indicator must cover at least the area of a 2 CSS pixel line around the control. And those pixels must change by a contrast ratio of at least 3:1 between unfocused and focused.

Take a button 90 by 30 CSS pixels. Its minimum area is 480 square pixels. The simplest way to pass is a solid outline at least 2 CSS pixels thick.

The change of contrast is a different test from 1.4.11. It compares the same pixels before and after focus, not side by side. A background that changes from black to dark grey fails.

2.4.13 doesn’t apply if the browser draws the indicator and you can’t change it. It doesn’t apply either if you haven’t changed the indicator or the background behind it.

When a modal dialog opens, focus should move inside it. Tab and Shift+Tab should loop round its controls, and Esc should close it. When it closes, focus should go back to the button that opened it.

That’s the pattern in the modal dialog guide. The guide also strongly advises a visible close button in every dialog.

DWP’s sixth check asks for focus to stay inside any open pop-up. WCAG is less strict for pop-ups that aren’t modal. A passing non-modal dialog can let focus move on to the rest of the page. Follow DWP’s stricter check for anything that covers the page, since focus moving behind it gets hidden.

A dialog or menu should also sit right after the button that opens it in the focus order. When it doesn’t, that’s failure F85.

In tabs, menus and grids, Tab usually reaches the group once, and the arrow keys move inside it. Focus and selection aren’t the same thing. A selected tab keeps its look while focus moves on, so check you can tell which is which.

2.1.4 Character Key Shortcuts is Level A. If a shortcut uses only a letter, number or symbol, you must be able to turn it off or change it. Or it must only work when its part of the page has focus.

These shortcuts are easy to set off by mistake, for keyboard users and some speech input users. Picture a user who hits S by accident, jumps to the search box and loses their place.

To test it, check the site’s help or settings for single-key shortcuts. Then try them with focus somewhere else on the page.

3.2.1 On Focus is Level A. It says that moving focus to something must not change the context. Sending a form, opening a new window and moving focus somewhere else all count as a change.

DWP’s seventh check tests this. All actions should be on purpose, because something that acts as soon as it gets focus can lead people to send things they didn’t mean to.

A help box that opens when a field gets focus fails. It pulls focus away each time the user tries to tab past.

A drop-down of pages that only jumps when you pick one with Space or Enter passes. Moving through the list changes nothing, so focus stays where the user puts it.

W3C names each common failure with a code. These are the keyboard ones.

  • A function that only works with mouse or touch events is F54 (2.1.1).

  • A script that takes focus away as soon as something gets it is F55 (2.1.1, 2.4.7, 2.4.13 and 3.2.1).

  • Content formats mixed in a way that traps users in one of them is F10 (2.1.2).

  • Single-key shortcuts that users can’t turn off or change are F99 (2.1.4).

When focus seems to stop working, two causes are common. Either someone removed the outline in the CSS, or focus got lost when a dialog closed. The ARIA guide says that if closing a dialog removes the focused element and nothing moves focus, the browser drops it back to the top of the page. That part of the guide is marked unfinished.

Write up each check as you go, in DWP’s order. For each fail, note the page, the browser, the key you pressed and what happened. Add the WCAG number and level, so the team can sort the fixes.

For how to write up issues so someone else can repeat them, see the writing-up part of how to test website accessibility.

W3C also publishes test rules for some of these checks. You don’t have to use them to meet WCAG.

A keyboard pass is one part of a full test. W3C says no tool can decide whether a site is accessible. The wider test, with automated tools and screen readers, is in the main testing guide.

Screen readers change how keys work. Windows screen readers have a browse mode that catches most key presses before the page gets them. So test with the keyboard on its own first, then with a screen reader.

Whether you must meet WCAG by law depends on where you are. For the UK, see UK accessibility law. For a full audit, see what is a WCAG audit.

Accessibility Testing runs accessibility audits that end in a written audit report against WCAG 2.2 AA.


I've designed products for more than ten years, leading accessibility and design system work for product teams. I also built Perception, a Figma plugin that checks contrast while you design.

Sources

Every rule on this page comes from the group that wrote it or the service that runs the check.

Talk to us about an audit

Book a 25-minute call and tell us what you need checked.

Book a 25-minute call