Free, independent guides since 2010

Accessibility

Keyboard accessibility: a site you can use without a mouse

How to make websites fully keyboard accessible: focus order, visible focus styles, skip links, custom widgets, keyboard traps, modals and menus, and how to test with Tab, Shift+Tab, Enter, Space and arrows.

<guide section="Accessibility" type="article" read="1 min"/>

Test your site by pressing Tab. Can you see where you are? Can you reach the menu, the search, the buttons and the form? Can you open and close everything? If not, some visitors cannot use your site at all.

Keys to test with

KeyExpected behaviour
Tab / Shift+TabMove forward and back between interactive elements
EnterActivate links and buttons
SpaceActivate buttons, toggle checkboxes
Arrow keysMove within menus, tabs, radio groups, sliders
EscapeClose dialogs, menus and popups

Visible focus

CSS
:focus-visible {
  outline: 3px solid #8f1418;
  outline-offset: 2px;
  border-radius: 4px;
}

Make sure sticky headers do not cover the focused element (WCAG 2.2, see WCAG explained).

HTML
<a class="skip" href="#main">Skip to content</a>
…
<main id="main">…</main>

This site has one: press Tab on any page and it appears.

Use native elements

  • <a href> for navigation, <button> for actions – not clickable <div>s.
  • Native form controls instead of custom lookalikes.
  • <details> and <dialog> where they fit.

Common problems

  • Dropdown menus that open on hover only (see accessible navigation).
  • Modals that do not trap focus inside, or do not return focus when closed.
  • Keyboard traps: focus gets stuck in an embedded widget.
  • Focus order that jumps around because of CSS reordering.
  • Carousels that cannot be paused or controlled.

Frequently asked questions

Why should I care about keyboard users?

People who are blind, have motor disabilities or use switch devices rely on keyboard-like navigation. Power users and people with temporary injuries benefit too.

Can I remove the focus outline because it looks ugly?

Never remove it without a clear replacement. Style it to fit your design instead – :focus-visible lets you show it only for keyboard users.