Accessibility Certified – Home

Getting there without a mouse

Many people use the web without a mouse: with a keyboard, switches, voice control or a screen reader. Here is what has to work for them and how to manage focus properly in modern web apps.

Last reviewed: · 6 min read

The ground rules

Real buttons, not clickable divs

A <button> is focusable out of the box, responds to Enter and Space and is announced as a button. A <div> with a click handler does none of that. Use <button> for actions and <a href> for navigation. Less code, fewer bugs.

Problem
<div class="btn" onclick="save()">
  Save
</div>
Better
<button type="button" class="btn">
  Save
</button>

The button is focusable, works with Enter and Space and has the right role.

tabindex: 0 and -1 yes, positive values no

tabindex="0" adds an element to the natural tab order, for example a custom widget. tabindex="-1" makes an element focusable by script without putting it in the tab order, for example a heading you move focus to after a route change. Positive values such as tabindex="3" scramble the order and are almost never the right fix. Arrange the HTML in the order it should be read instead.

Route changes in single-page apps

On a traditional website a click loads a new page and the screen reader starts at the top. In a single-page app, JavaScript swaps the content. Focus stays on the link that was clicked, which may no longer exist, and nobody is told that anything changed.

A proven approach: after each route change, update document.title (2.4.2 Page Titled) and move focus to the new main heading. Alternatively, announce the change through a live region, as shown in our pattern status message.

Problem
router.on('change', view => {
  main.innerHTML = view.html;
});
Better
router.on('change', view => {
  main.innerHTML = view.html;
  document.title = view.title;
  const h1 = main.querySelector('h1');
  h1.setAttribute('tabindex', '-1');
  h1.focus();
});

Dialogs, menus and returning focus

When a modal dialog opens, focus moves into it. While it is open, Tab stays inside, Escape closes it, and afterwards focus returns to the element that opened it. The native <dialog> element with showModal() handles much of this for you. See it in action in our pattern modal dialog, and for menus in disclosure navigation.

Note: trapping focus is right only for genuinely modal dialogs. Anywhere else it is a keyboard trap.

Custom shortcuts, used with care

Single-character shortcuts, such as “s” for search, fire by accident with voice control. 2.1.4 Character Key Shortcuts requires that such shortcuts can be turned off or remapped, or only work while the relevant component has focus. Shortcuts with Ctrl or Alt are not affected.

Checklist

0 of 8 done

Your ticks stay in this browser tab only and are not stored anywhere.

Related WCAG criteria

Tools and patterns for this

Frequently asked questions

What is the quickest keyboard test?

Put the mouse aside and go through one key journey using Tab, Shift+Tab, Enter, Space and Escape. Watch whether focus is always visible and whether you can always get out again.

Do custom widgets need arrow keys?

Composite widgets such as tabs, menus or listboxes are expected to behave as described in the WAI-ARIA Authoring Practices Guide, usually with arrow keys. Simple buttons and links do not need them.

What about hover menus?

Anything that appears only on mouse hover is often out of reach for keyboard and touch users. Open sub-menus with a button that carries aria-expanded.

Sources

How does your website do?

The free check tests your home page in two minutes. The audit decides all 55 criteria, by a person.

Free checkSee pricing

More guides

  • Cookie banners that lock no one out

    The cookie banner is often the first thing visitors meet, and for some the last: if it cannot be used with a keyboard or screen reader, the site is closed to them. Here is how to get it right.

  • Contrast that everyone can read

    Pale grey text may look refined, but many people struggle to read it, and on a phone in bright sunlight everybody does. Here are the ratios WCAG 2.2 sets and how to lock them into your design.

  • EAA compliance check: how to get your website tested for accessibility

    The European Accessibility Act asks for accessible services, not for a particular test. This guide explains what each kind of check can tell you, how an audit works, what ours costs, and what you hold at the end.