Guide
Keyboard navigation and focus: how to test and fix your website
A website works with a keyboard if you can reach and use every link, button and field with the Tab, Enter, Space and arrow keys, and always see where you are. Many people cannot use a mouse, including people with motor disabilities and screen reader users. Testing takes five minutes, and the fixes are mostly about showing focus and fixing menus.
The basics
Why the keyboard matters
Not everyone points and clicks. People who have tremors, limited hand movement or repetitive strain, people who use switches or voice control, and blind people using screen readers all move around a page with the keyboard or something that behaves like one. If a menu opens only when you hover over it, or a button cannot be reached with Tab, those visitors are stuck.
Keyboard access is also a fast way to find many other problems. A page that works well with the keyboard is usually built from proper links, buttons and headings, which also helps screen readers and search engines.
WCAG has several rules about it. Everything must be operable from the keyboard, you must never trap focus in a part of the page, and the element with focus must be visible.
Test it
A five-minute keyboard test
Click the page, then press Tab
Focus should move to the first link or button. Keep pressing Tab and watch where it goes.
Check you can always see focus
A clear outline or highlight should show which element you are on. If it vanishes, that is a failure.
Use the menus
Open the main menu and sub-menus with Tab, Enter and the arrow keys. Make sure you can reach every item and close the menu again with Escape.
Press Enter and Space
Links should work with Enter. Buttons should work with Enter and Space. Fill in and submit a form.
Look for traps
If you tab into a pop-up or video and cannot get out, you have found a keyboard trap. Fix it first.
Fixes
Common keyboard problems and how to fix them
| Problem | What the visitor sees | Fix |
|---|---|---|
| Focus outline removed with CSS | No idea where they are on the page | Restore a clear outline, or design a visible focus style |
| Menu opens only on hover | Keyboard users cannot open it | Make it open on focus or with a button press |
| A clickable box made from a div | Tab skips it | Use a real link or button element |
| A pop-up that traps focus | Cannot get back to the page | Add a close button and return focus when it closes |
| No way to skip the navigation | Must tab through every link on every page | Add a "Skip to content" link at the top |
| A sticky header covering focused items | The focused link is hidden | Add scroll padding so focus is never hidden |
Good structure
Skip links, headings and landmarks
A skip link is a link at the very top of the page, usually hidden until it receives focus, that jumps straight to the main content. It saves a keyboard user from tabbing through the whole menu on every page. Many modern themes include one, so check yours does.
Headings and landmarks help screen reader users jump around. Use one main heading per page, then sub-headings in order. Use proper regions for the header, navigation, main content and footer, which most themes do for you.
Our guide to WCAG for small business sites shows how keyboard access fits with the other rules, and the forms guide covers the keyboard side of forms.
Common mistakes
Mistakes that break keyboard access
The most common mistake is removing the focus outline because a designer finds it ugly. A line of CSS that hides it takes away the only signal keyboard users have. If you dislike the default, design your own, with a thick, high-contrast outline or a clear background change.
Another is using the wrong elements. A clickable box made from a plain div looks like a button but is invisible to the keyboard unless extra code is added. A real link or button element works with Tab, Enter and Space with no extra work, and screen readers announce it correctly.
A third is changing the visual order of the page with CSS so that it no longer matches the order in the code. Tab follows the order in the code, so focus jumps around unpredictably. Keep the two in step.
Finally, watch out for embedded content such as maps, videos and booking widgets from other companies. Test each one with the keyboard. If a widget traps focus, ask the supplier for a fix, or offer another way to do the same task, such as a phone number or an email link.
Before you publish
A keyboard checklist
- You can reach every link, button and field with Tab
- The focused item is always clearly visible
- Focus order follows the visual order of the page
- Menus open with the keyboard and close with Escape
- There is a skip link to the main content
- Pop-ups can be closed with the keyboard and return focus
- You never get stuck in a widget or embedded map
- Buttons work with Enter and Space, links with Enter
- Sticky headers do not hide the focused item
- Forms can be completed and sent without a mouse
Beyond the basics
Testing on a phone and with assistive tools
Keyboard access is also the foundation for other tools. Switch devices and voice control software use the same focus order as the keyboard, so fixing it helps them too. On a phone, test that tap targets are large enough and not packed too closely together, which WCAG 2.2 now asks for.
Once the keyboard test passes, try a screen reader for a few minutes on your home page and contact page. Notice whether headings, links and buttons are announced sensibly. Small fixes to labels and heading order often make a large difference.
A fast, secure home for an accessible site
UK servers in London, free SSL and live chat open 24/7 on every plan, from 84p a month (£10.03 billed yearly).
FAQ
Common questions
How do I test keyboard access?
Put the mouse aside and use Tab, Shift+Tab, Enter, Space, the arrow keys and Escape to move through and use the page.
What is a keyboard trap?
A part of a page you can tab into but cannot leave with the keyboard, often a pop-up or embedded widget.
Is it fine to hide the focus outline?
No. Visible focus is required, so replace the default outline with a clear style if you dislike it.
What is a skip link?
A link at the top of the page that jumps to the main content, so keyboard users can avoid tabbing through the navigation.
Do hover menus fail?
If they cannot be opened with the keyboard, yes. Make them open on focus or with a button.
Keep reading
Related pages
Host your accessible site in the UK
Free SSL and live chat on every plan, with a 15-day money-back guarantee.