Keyboard and focus: using a site without a mouse

TL;DR

Difficulty: Intermediate

Everything that works with a mouse must work with a keyboard (WCAG 2.1.1, Level A), because screen readers, voice control and switches all travel the same road.

  • Use native elements: button for actions, a for destinations, radio buttons for a choice of one, dialog for a window on top.
  • Keep a strong focus outline (3:1 contrast), add a skip link, keep source order equal to reading order.
  • Menus need a real button that says whether the menu is open. Modal windows move focus in, keep it inside, and give it back on close.
  • Test by putting the mouse away for five minutes, then automate the key paths.

Some of your customers never touch a mouse. They move through your shop with Tab, Enter and Escape, or with a screen reader, voice control or a switch that behaves like a keyboard. Here is who they are, the WCAG rules that keep them moving, and the code to fix the places where most shops stop them, worked through on one invented Galway bookshop.

The short answer: whatever works with a mouse must work with a keyboard

Picture a customer who cannot use a mouse. Not a rare edge case, just someone whose hands, eyes or circumstances make pointing at small things on a screen slow, painful or impossible. They move through your site with the keyboard instead: Tab to go forward, Shift and Tab to go back, Enter or Space to press things, Escape to close things, the arrow keys to move inside a group.

The thing that makes this work is called focus. Focus is the one element on the page that is currently listening to the keyboard. Press Tab and focus moves to the next link, button or field. Press Enter and whatever has focus does its job. A mouse user points and clicks. A keyboard user moves focus and presses a key.

The Web Content Accessibility Guidelines (WCAG) put the rule in one line: all functionality must be operable through a keyboard interface (success criterion 2.1.1, Level A).1 This article covers who relies on the keyboard, the WCAG rules that keep them moving, the native HTML that does most of the work for free, and the three places most shops break: the focus style, the mobile menu and the pop up window.

The series example is Claddagh Books, an independent bookshop in Galway with an online shop at claddaghbooks.example. Sinéad owns it, Ade builds and looks after the site. Everything about the shop, its customers and its numbers is invented to explain the ideas.

Who uses a website without a mouse

The W3C's own explanation of the keyboard criterion names the groups plainly. Keyboard access lets people with no vision use a site, because a mouse depends on seeing where the pointer is. It serves people who use alternate keyboards or input devices that act as a keyboard, a group the W3C lists as including speech input software, sip and puff software, on screen keyboards and scanning software. And it helps people with low vision, who may find it hard to track a pointer at all.2 WebAIM, the accessibility team at Utah State University, adds that many users with motor disabilities rely on a keyboard, and that some sighted users simply prefer it because it is faster.3

So the keyboard is not one niche. Screen readers, voice control and switches all lean on the same keyboard support, which makes it the common road most assistive technology drives on.

The World Health Organization estimates that 1.3 billion people, about 16% of the world's population, experience significant disability.4 Not all of them need the keyboard, and plenty who do would not call themselves disabled: a broken wrist in plaster, a baby in one arm, a dead trackpad.

Voice control adds one rule worth knowing early. Success criterion 2.5.3, Label in Name (Level A), says that when a control has a visible text label, its accessible name, the name assistive technology reads out, must contain that visible text.5 The reason is practical: a voice user says what they can see. If the button reads "Add to basket" but its hidden name is "Purchase item 4471", the spoken command finds nothing.5

Example: three Claddagh Books customers and what each needs

Ade writes down three invented regulars before he touches any code.

Declan has used the keyboard instead of a mouse since a stroke left his right hand weak. He shops with his left hand on the keys. He needs every link and button to be reachable with Tab, a focus outline he can see clearly, and no step that only works by dragging or hovering.

Aoife is blind and uses the NVDA screen reader on a Windows laptop. She moves by Tab and by the screen reader's own shortcuts, such as jumping from heading to heading. She needs every control to announce what it is and what it does, and she needs pop up windows to take her into them and bring her back out to where she was.

Cian broke his wrist at hurling training and is using voice control on his Mac for six weeks. He needs the names of buttons to match the words printed on them, so that "click Quick view" does what he expects.

Three people, three tools, one shared requirement: the site has to work without a mouse. Ade tests every fix below against all three.

The WCAG rules that keep a keyboard user moving

WCAG is the standard most accessibility law in Europe points to, and Level AA is the line those laws draw. I explain the structure in WCAG 2.1 AA explained. For the keyboard, a short list of success criteria does nearly all the work. WCAG 2.1 is the version the law currently relies on, and WCAG 2.2 adds one keyboard criterion at Level AA that is worth meeting anyway.16

CriterionLevelWhat it asks, in plain words
2.1.1 KeyboardAEverything works from the keyboard, without needing precise timing.1
2.1.2 No Keyboard TrapAIf focus can get into something, the keyboard can get it out again.1
2.4.1 Bypass BlocksAThere is a way to skip blocks that repeat on every page, such as the menu.1
2.4.3 Focus OrderAFocus moves in an order that keeps the meaning and the task intact.1
2.4.7 Focus VisibleAAYou can see where focus is.1
2.4.11 Focus Not Obscured (Minimum)AA, new in 2.2The focused item is never completely hidden behind something else on the page, such as a sticky header or a cookie banner.67
2.4.13 Focus AppearanceAAA, new in 2.2The focus indicator is large enough and contrasts at least 3:1 with its unfocused state.68

Focus Appearance, 2.4.13, sits at Level AAA, so it is not part of the AA target.8 It still makes a good design guide, because its measure (an outline at least as large as a 2 CSS pixel border around the control, with 3:1 contrast between focused and unfocused) answers "how visible is visible enough".8

The European standard EN 301 549 carries the WCAG web criteria into its clause 9, so a site that meets these at AA is meeting the benchmark the European Accessibility Act relies on.9

Example: Declan buys a book, one rule at a time

Ade traces Declan's purchase of a paperback as it should run once the fixes in this article are in, and notes which criterion each moment depends on.

  1. Declan lands on the home page and presses Tab. A "Skip to main content" link appears first, he presses Enter and jumps past the 22 links of the header. That is 2.4.1.
  2. He tabs to the search box, types a title, presses Enter. The results page loads, and the first Tab after the skip link lands on the first result, not on something in the footer. That is 2.4.3.
  3. At every step a thick dark outline shows him where he is. That is 2.4.7, and the outline's size and contrast follow the 2.4.13 measure.
  4. He opens the "Quick view" for a book. Focus moves into the window, he can tab through its buttons, and Escape takes him back out to the same "Quick view" button. That is 2.1.1 and 2.1.2.
  5. As he tabs down the product page, the sticky header never covers the link he is on. That is 2.4.11.

If any one of the five fails, Declan is stuck on that step, and the sale with him.

The single most common keyboard failure has nothing to do with clever widgets. It is a <div> or a <span> that someone made clickable with JavaScript and styled to look like a button.

A real <button> element comes with everything for free: it is in the Tab order, Enter and Space both press it, and it tells assistive technology "I am a button" along with its label. A <div> has none of that. It cannot be reached with Tab, a key press does nothing, and a screen reader announces it as plain text, if at all. MDN, the web documentation project run by Mozilla, says it directly: avoid using a <div> to describe a button instead of the <button> element, because components built from non interactive elements are not exposed properly to assistive technology.10

The rule for choosing between the two native elements is short. A link goes somewhere: another page, or a place on this page. A button does something: adds to the basket, opens a window, submits a form. Use <a href="..."> for the first and <button type="button"> for the second, and keyboard behaviour follows without a single extra line of code.

ARIA, short for Accessible Rich Internet Applications, is a set of attributes that tell assistive technology what a custom element is meant to be. It can describe, it cannot behave: adding role="button" to a <div> makes a screen reader call it a button, but Tab still skips it and Enter still does nothing until you write that behaviour yourself.

Example: the "Add to basket" button on Claddagh Books

Ade finds the product page's main button built like this:

<!-- Broken: looks like a button, is not one -->
<div class="btn btn-primary" onclick="addToBasket(4471)">
  Add to basket
</div>

Here is what each part does for a keyboard user. The class only changes the look. The onclick only listens for a mouse click (or a tap). There is no tabindex, so Tab never reaches it, and there is no role, so Aoife's screen reader reads "Add to basket" as an ordinary line of text. Declan cannot buy the book at all.

The fix is one element:

<!-- Fixed: a real button -->
<button type="button" class="btn btn-primary" data-book-id="4471">
  Add to basket
</button>

<button> puts it in the Tab order and makes Enter and Space press it. type="button" stops it from submitting a surrounding form by accident, which is the default for a button inside a form. data-book-id keeps the book's number on the element so one script can serve every button on the page. The visible text, "Add to basket", is also the accessible name, so Cian can say "click Add to basket" and it works, which meets 2.5.3.5

The shop's newer pages use React. Same mistake, same fix:

// Broken
<div className="btn btn-primary" onClick={() => addToBasket(book.id)}>
  Add to basket
</div>

// Fixed
<button type="button" className="btn btn-primary" onClick={() => addToBasket(book.id)}>
  Add to basket
</button>

Ade then searches the codebase for onclick and onClick on anything that is not a <button> or an <a>. He finds 14 more, including the newsletter "Close" cross and the "Show more reviews" toggle, and changes each one the same way.

A focus style people can actually see

The second most common failure is a design decision. Browsers draw a focus outline by default, and somebody finds it ugly on a mouse click and removes it with one line of CSS. Mouse users never notice. Keyboard users lose their place on every page. WebAIM's advice is blunt: avoid outline: 0, outline: none or any style that removes or limits the visibility of the keyboard focus indicator.3

There is a better way to satisfy the designer. The CSS selector :focus-visible matches an element only when the browser judges that focus should be shown, which in practice means when someone arrives by keyboard, and usually not when someone clicks a button with a mouse.11 So the mouse click stays clean and the keyboard user gets a strong outline.

How strong? Success criterion 1.4.11, Non text Contrast, asks for at least 3:1 contrast for the visual parts that identify a control and its state, and MDN applies it to the focus indicator.11 The 2.4.13 measure gives the size: at least as large as a 2 CSS pixel line all round the control.8 How to measure contrast is covered in my article on accessible charts, colour contrast and screen readers, so I will not repeat the formula here.

The last trap is the sticky header. A header that stays at the top while you scroll is handy, until the browser scrolls a focused link up underneath it and it disappears completely. That fails 2.4.11.7 The W3C's guidance lists sticky headers, sticky footers and cookie banners as the usual culprits, and suggests scroll padding so the browser leaves room for them.7

Example: a visible focus ring for Claddagh Books

Ade finds this in the shop's stylesheet:

/* Broken: the focus outline removed everywhere */
*:focus {
  outline: none;
}

He deletes it and adds:

/* Fixed: a clear outline whenever focus arrives by keyboard */
:focus-visible {
  outline: 3px solid #1d1d1b;
  outline-offset: 3px;
}

/* Leave room for the 72 pixel sticky header when the browser scrolls to focus */
html {
  scroll-padding-top: 88px;
}

Line by line. :focus-visible targets keyboard focus. outline: 3px solid #1d1d1b draws a near black line, three pixels thick, which clears the 2 pixel size guide. outline-offset: 3px moves it a little away from the control so it does not merge into the button's own border. scroll-padding-top tells the browser to stop scrolling 88 pixels short of the top, so a focused link always lands just below the 72 pixel header with a little air.

The shop's background is a pale cream and its buttons a deep sea green. Ade measures the outline against both and both clear 3:1 comfortably. Then he tabs through the home page as Declan would: on the old site focus vanished behind the header three times, now he can see it on all 40 stops.

Most shop pages start with the same block: logo, search, account, basket, categories. A mouse user skips it with their eyes. A keyboard user tabs through every item, on every page. Success criterion 2.4.1 asks for a way to bypass blocks like that.1

The simplest answer is a skip link: the very first link on the page, hidden until it receives keyboard focus, that jumps straight to the main content. The GOV.UK Design System, the UK government's shared component library, publishes one. Its guidance is to place it immediately after the opening <body> tag (or straight after a cookie banner if there is one), keep it out of the <nav>, and keep it visually hidden until a key press brings focus to it.12

Ade counts the Tab presses from the top of the Claddagh Books results page to the first book: 23, because the header holds 22 links and controls. The figures in this chart are from the invented example.

Bar chart from the invented Claddagh Books example. Without a skip link a keyboard user needs 23 Tab presses to reach the first book in the search results. With a skip link it takes one Tab press and one Enter, two key presses in total. Tap or click to open full screen and move around

He adds the link to the shop's main layout. The shop runs on Ruby on Rails, so the layout is an ERB template:

<body>
  <%= link_to "Skip to main content", "#main-content", class: "skip-link" %>
  <%= render "layouts/header" %>
  <main id="main-content" tabindex="-1">
    <%= yield %>
  </main>
  <%= render "layouts/footer" %>
</body>

link_to writes an ordinary <a href="#main-content">. id="main-content" on the <main> element is where the link lands. tabindex="-1" lets the browser move focus to <main> when the link is followed, without adding <main> to the Tab order. MDN describes exactly this use of a negative value.10 yield is where Rails puts each page's content.

And the CSS that keeps the link out of sight until it is needed:

.skip-link {
  position: absolute;
  left: 1rem;
  top: -100px;
}
.skip-link:focus {
  top: 1rem;
}

The link sits above the top edge of the screen until it receives focus, then drops into view. For Declan the results page now takes two key presses, Tab and Enter, instead of 23.

Focus order follows the reading order

Success criterion 2.4.3 asks that focus moves in an order that keeps the meaning and the task intact.1 In practice that means the order of elements in the HTML source should match the order a sighted person reads the page. Focus follows the source, not the screen.

Two habits break it. The first is a positive tabindex, such as tabindex="1", used to force one element to the front. MDN recommends using only 0 and -1 and warns that values above zero make a page hard to use for anyone navigating by keyboard.10 The second is CSS that reorders things visually, such as flexbox order or a reversed row, while the HTML stays in the old order. MDN names CSS properties that change the order of focusable elements in the same warning.10 The page looks right and tabs wrong.

Example: the product page that jumped around

On the Claddagh Books product page the "Add to basket" button sits visually right next to the price. In the HTML, though, it comes after the full description, the author biography and twelve customer reviews, and CSS lifts it up into place. So when Declan tabs from the price, focus vanishes down the page through every "Helpful" button in the reviews before landing on "Add to basket", and the screen scrolls wildly to follow it.

Ade moves the button's HTML directly after the price and removes the CSS that repositioned it. Tab from the price now goes to the format choice, then "Add to basket", then into the description. The page looks exactly the same. Only the source order changed, and with it the keyboard path.

The mobile menu: a button that says what it does

On a phone, and on a laptop zoomed to 200%, which is how many people with low vision browse, most shops collapse the menu behind a single icon. That icon is where a lot of keyboard access quietly dies: it is often a <div> with three lines drawn in CSS, it cannot be reached with Tab, and nothing tells a screen reader whether the menu is open or shut.

The W3C's ARIA Authoring Practices Guide (APG), the reference for building custom widgets, has a pattern for exactly this, the disclosure navigation menu. A real button shows and hides the list of links. The button carries aria-expanded, set to true when the list is showing and false when it is hidden, and aria-controls, which points at the list it controls. Escape closes an open menu and puts focus back on its button.13 The guide also says why it deliberately does not use the ARIA menu role: ordinary site navigation does not have the complex behaviour assistive technology expects from a widget with that role.13 A list of links in a <nav> is the right shape.

Example: rebuilding the Claddagh Books mobile menu

The old menu:

<!-- Broken: an icon nobody can reach or understand -->
<div class="menu-icon" onclick="toggleMenu()"></div>
<ul class="menu" style="display: none">
  <li><a href="/books">Books</a></li>
  <li><a href="/events">Events</a></li>
  <li><a href="/gift-cards">Gift cards</a></li>
  <li><a href="/visit">Visit the shop</a></li>
</ul>

Declan cannot tab to the icon. Aoife hears nothing at all where the icon is. Cian has no word to say, because there is no text.

The new one:

<!-- Fixed: a disclosure button and a labelled navigation region -->
<nav aria-label="Main">
  <button type="button" class="menu-toggle" aria-expanded="false" aria-controls="main-menu">
    Menu
  </button>
  <ul id="main-menu" hidden>
    <li><a href="/books">Books</a></li>
    <li><a href="/events">Events</a></li>
    <li><a href="/gift-cards">Gift cards</a></li>
    <li><a href="/visit">Visit the shop</a></li>
  </ul>
</nav>

Every attribute, in order. <nav aria-label="Main"> marks this as the main navigation, so a screen reader user can jump straight to it. <button type="button"> is a real button, reachable with Tab and pressed with Enter or Space. The visible word "Menu" is its name, which Aoife hears and Cian can say. The three line icon, if Sinéad wants it, goes beside the word as decoration. aria-expanded="false" tells assistive technology the list is currently closed. aria-controls="main-menu" points at the list by its id. hidden on the list removes it from the screen and from the Tab order until the button opens it.

The script that makes it work:

const toggle = document.querySelector('.menu-toggle')
const menu = document.getElementById('main-menu')

function setMenu(open) {
  toggle.setAttribute('aria-expanded', String(open))
  menu.hidden = !open
}

toggle.addEventListener('click', () => {
  setMenu(toggle.getAttribute('aria-expanded') !== 'true')
})

document.addEventListener('keydown', (event) => {
  if (event.key === 'Escape' && toggle.getAttribute('aria-expanded') === 'true') {
    setMenu(false)
    toggle.focus()
  }
})

setMenu keeps the two things in step: the attribute that tells assistive technology the state, and the hidden property that shows or hides the list. The click listener fires for a mouse click, a tap, and Enter or Space on the button, because that is what a native button does, so one listener serves everyone. The keydown listener closes an open menu on Escape and returns focus to the button, as the APG pattern describes.13 On a wide screen, a media query in the CSS shows the list and hides the button, so the same HTML serves both layouts.

Ade tests it three ways. Declan: Tab to "Menu", Enter, Tab through the links, Escape, and focus is back on "Menu". Aoife: NVDA announces "Menu, button, collapsed", then "expanded". Cian: "click Menu" opens it, "click Events" follows the link.

Pop up windows: move focus in, keep it there, give it back

A modal dialog is a window that opens on top of the page and must be dealt with before you carry on: a quick view of a product, a size guide, a "Are you sure you want to empty your basket?" question. It is the hardest common pattern to get right by keyboard, and the APG sets out what it must do. When the dialog opens, focus moves to an element inside it. Tab and Shift and Tab move only between the controls inside it. Escape closes it. When it closes, focus returns to the element that opened it.14

The good news is that the HTML <dialog> element, opened with its showModal() method, does most of that for you. MDN describes what the browser provides. The rest of the page becomes inert, which means nothing behind the dialog can be focused or clicked. Escape closes the dialog. Focus moves into the dialog when it opens, and the autofocus attribute lets you choose where.15 MDN also notes that the most robust way to make sure everyone can close a dialog is a visible close button.15 Write the return of focus to the button that opened the dialog yourself, in a line of script, so the behaviour is explicit and easy to test.

This is the flow every modal should follow:

Tap or click to open full screen and move around

Example: the "Quick view" window on Claddagh Books

The old quick view was a <div> that faded in over the page. When Declan pressed Enter on "Quick view" the window appeared, but focus stayed on the page behind it. His next Tab moved through links he could no longer see, hidden under the grey overlay. The only way to close the window was a small cross that was itself a <span>, so he could not close it at all. That fails 2.1.1, and in practice it traps him.1 Aoife heard nothing when the window opened, because nothing told her screen reader it was there.

Ade rebuilds it. First the trigger on each book in the results list:

<button type="button" class="quick-view" data-dialog="qv-salt-road">
  Quick view<span class="visually-hidden">: The Salt Road</span>
</button>

The visible text is "Quick view". The extra words, hidden visually by a standard visually-hidden CSS class but still read aloud, make the name "Quick view: The Salt Road", so Aoife knows which of the twenty "Quick view" buttons she is on. The full name starts with the visible words, so Cian's "click Quick view" still matches, as 2.5.3 requires.5

Then the dialog itself:

<dialog id="qv-salt-road" aria-labelledby="qv-salt-road-title">
  <h2 id="qv-salt-road-title" tabindex="-1">The Salt Road</h2>
  <p>Paperback, €12.99. In stock at the Galway shop.</p>
  <button type="button" class="add-to-basket" data-book-id="4471">Add to basket</button>
  <button type="button" class="close-dialog">Close</button>
</dialog>

<dialog> is the native element. aria-labelledby points at the heading, so the dialog is announced by its title. tabindex="-1" on the heading lets the script place focus there without adding the heading to the Tab order, which suits a window that starts with information to read, as the APG suggests for content like this.14 The close control is a real <button> with the word "Close", reachable, pressable and sayable.

And the script:

document.querySelectorAll('[data-dialog]').forEach((trigger) => {
  const dialog = document.getElementById(trigger.dataset.dialog)

  trigger.addEventListener('click', () => {
    dialog.showModal()
    dialog.querySelector('h2').focus()
  })

  dialog.querySelector('.close-dialog').addEventListener('click', () => {
    dialog.close()
  })

  dialog.addEventListener('close', () => {
    trigger.focus()
  })
})

showModal() opens the dialog as a modal, so the page behind goes inert and Escape works.15 focus() on the heading puts Aoife and Declan at the top of the window. The close button calls close(). The close event fires however the dialog was closed, by the button, by Escape or by the "Add to basket" script, and sends focus back to the exact "Quick view" button that opened it.

Now Declan presses Enter on "Quick view: The Salt Road", lands on the title, tabs to "Add to basket" and "Close", presses Escape and is back on the same button, ready for the next book. Aoife hears the dialog announced by its title and, on closing, is returned to where she was in the list.

Custom widgets: when ARIA helps and when it hurts

Sometimes a design asks for something HTML does not have built in, a tab panel, a carousel, a combined search box with suggestions. That is where ARIA earns its place, and where it most often goes wrong.

The W3C's Using ARIA note sets out the rules (it is now a discontinued draft that sends readers to the APG for detailed guidance, but its rules still stand as the plainest summary).16 The first: use the native element when one exists. The second: do not change native semantics unless you really have to. The fourth: never put role="presentation" or aria-hidden="true" on something that can receive focus, because some users will then land on nothing.16

The practical reading for a shop is a decision you can make in a minute, and it looks like this:

Tap or click to open full screen and move around

Example: the format picker that became radio buttons

Claddagh Books sells many titles in three formats. The designer drew three tiles, Paperback, Hardback and Audiobook, and the old code built them as three <div> elements with a click handler and an aria-selected attribute borrowed from a tab widget. Aoife's screen reader announced "selected" with no idea what kind of control it was, and Declan could not reach the tiles at all.

Ade asks the first question in the flow: is there a native element for "choose exactly one of three"? There is, a group of radio buttons:

<fieldset class="format-picker">
  <legend>Format</legend>
  <label><input type="radio" name="format" value="paperback" checked> Paperback, €12.99</label>
  <label><input type="radio" name="format" value="hardback"> Hardback, €21.99</label>
  <label><input type="radio" name="format" value="audiobook"> Audiobook, €16.99</label>
</fieldset>

<fieldset> and <legend> group the three and give the group its name, so Aoife hears "Format, grouping" before the options. Each <label> wraps its <input>, so the words are the radio button's name and clicking the words selects it. name="format" makes the three one group, which gives keyboard users the behaviour WebAIM lists for radio buttons: Tab enters the group, the arrow keys move between options, and Tab leaves it again.3 checked marks the default.

The tiles still look like tiles, because CSS styles the labels as boxes. No ARIA was needed, and none was added. Forms like this one, with their labels, groups and error messages, are the whole subject of the chapter on accessible forms.

A five minute keyboard test anyone can run

You do not need special software for the first test. You need a keyboard, a page, and the willingness to put the mouse in a drawer. WebAIM publishes the standard keys for each kind of control, and they make a good checklist.3

  • Tab and Shift and Tab move forward and back between links, buttons and fields.
  • Enter follows a link. Enter or Space presses a button.
  • Space ticks or unticks a checkbox.
  • The arrow keys move between radio buttons in a group, and through the options of a select box.
  • Escape closes a dialog, or an open menu.

Then walk one real task, start to finish, and answer five questions at every step:

  1. Can I reach it with Tab?
  2. Can I see where I am, every time?
  3. Does the order make sense, in the same order I would read the page?
  4. Does the key I expect actually do the thing?
  5. Can I always get back out, without the mouse?

The manual test catches what tools miss, but you also want the computer to repeat it on every release so a fix never quietly breaks again. A browser test written with Playwright, a testing tool from Microsoft that drives real browsers, can press keys and check where focus ends up. Its documentation describes keyboard.press() for key presses and toBeFocused() for checking the focused element.17 The wider question of which tests to automate and where is covered in unit, integration and end to end tests, and accessibility testing as a whole is chapter 5, what tools find and what only people find.

Example: Sinéad runs the test herself, then Ade makes it permanent

Sinéad runs the five minute test herself on the path that pays the bills: search, quick view, add to basket, open the basket. Everything passes except one thing. In the basket, the quantity box shows no focus outline, because an old style still removes it on inputs. Ade deletes the stray rule, and that's grand.

Then he writes the quick view path as an automated test, so that if anyone ever breaks it again the release stops:

import { test, expect } from '@playwright/test'

test('quick view works by keyboard and returns focus', async ({ page }) => {
  await page.goto('/books?q=salt+road')

  const trigger = page.getByRole('button', { name: 'Quick view: The Salt Road' })
  await trigger.focus()
  await page.keyboard.press('Enter')

  const dialog = page.getByRole('dialog', { name: 'The Salt Road' })
  await expect(dialog).toBeVisible()

  await page.keyboard.press('Escape')
  await expect(dialog).toBeHidden()
  await expect(trigger).toBeFocused()
})

Read top to bottom, it is Declan's path in code: find the button by role and accessible name, as a screen reader would, press Enter, check the dialog is open, press Escape, check focus is back. Finding elements by role has a useful side effect: if someone turns the button back into a <div>, the test cannot find it and fails. The checkout around it is the shop's critical path, which is why chapter 3, an accessible checkout, tests the whole of it this way.

Whose job this is, and why a plugin cannot do it

In Ireland, the European Accessibility Act, Directive (EU) 2019/882, is law through S.I. No. 636 of 2023, the European Union (Accessibility Requirements of Products and Services) Regulations 2023, and it has applied since 28 June 2025.1819 The Competition and Consumer Protection Commission (CCPC) names eCommerce among the services covered and is the authority that checks compliance for it.20 Alongside it, the Equal Status Acts already prohibit discrimination on the ground of disability in the provision of goods and services, which includes an online shop.21 Who must comply, from when, and what the exemptions for microenterprises are, is set out in my article on accessibility law for online businesses.

Every fix in this article lives in the site's own HTML, CSS and JavaScript: which element a button is, what order the source runs in, where focus goes when a window opens. That is why accessibility is built, not bought. A script added on top of the page, the kind of overlay discussed in chapter 1, why overlays do not make your site compliant, cannot rewrite those decisions for you, and the legal duty stays with the business that runs the site either way.

This is how I work. I build sites and shops to WCAG 2.1 AA, with native HTML elements wherever possible and a visible focus style kept rather than removed, and I run the keyboard pass by hand on the key journeys alongside the automated checks that run on every build. My own website also has a small accessibility panel, built into the site's own code, that lets a visitor change text size, switch to high contrast and reduce motion. Those are preferences on top of a site built to work by keyboard and screen reader from the start. The panel is not what makes the site accessible, and it would be no substitute if the site underneath were not.

Conclusion: put the mouse away and fix what you find

Keyboard access is not a feature for a few. It is the road that screen readers, voice control, switches and plenty of tired or injured hands all travel on, and WCAG asks for it at Level A, the floor.1

Most of the work is choosing the right element: a <button> for actions, an <a> for destinations, radio buttons for a choice of one, <dialog> for a window on top. Keep the focus outline and make it strong. Add a skip link. Keep the source order the same as the reading order. Give the mobile menu a real button that says whether it is open, and give every pop up a way in, a way around and a way back.

Then put the mouse in a drawer for five minutes and try to buy something from your own shop. Whatever stops you is stopping a customer today, and every one of those fixes is yours to make.

Want to know where a keyboard user gets stuck on your shop? Book the free workshop: we walk your key paths with the mouse put away, and the first two weeks of fixing what we find are on me, no bother.

Sources

  1. 1.

    W3C, Web Content Accessibility Guidelines (WCAG) 2.1, W3C Recommendation, 5 June 2018, updated 6 May 2025 (success criteria 1.4.11, 2.1.1, 2.1.2, 2.4.1, 2.4.3, 2.4.7, 2.5.3 and 4.1.2), https://www.w3.org/TR/WCAG21/

  2. 2.

    W3C Web Accessibility Initiative, Understanding Success Criterion 2.1.1: Keyboard, Understanding WCAG 2.2 (intent: people with no vision, users of alternate keyboards and keyboard emulators such as speech input, sip and puff, on screen keyboards and scanning software, and people with low vision), https://www.w3.org/WAI/WCAG22/Understanding/keyboard.html

  3. 3.

    WebAIM, Keyboard Accessibility, Institute for Disability Research, Policy, and Practice, Utah State University (who relies on the keyboard, avoiding outline removal, avoiding positive tabindex, and the table of standard keystrokes), https://webaim.org/techniques/keyboard/

  4. 4.

    World Health Organization, Disability and health, fact sheet, 7 March 2023 (an estimated 1.3 billion people, about 16% of the world's population, experience significant disability), https://www.who.int/news-room/fact-sheets/detail/disability-and-health

  5. 5.

    W3C Web Accessibility Initiative, Understanding Success Criterion 2.5.3: Label in Name, Understanding WCAG 2.2 (Level A, speech input users activate controls by their visible label), https://www.w3.org/WAI/WCAG22/Understanding/label-in-name.html

  6. 6.

    W3C, Web Content Accessibility Guidelines (WCAG) 2.2, W3C Recommendation, 5 October 2023 (success criteria 2.4.11, 2.4.12 and 2.4.13), https://www.w3.org/TR/WCAG22/

  7. 7.

    W3C Web Accessibility Initiative, Understanding Success Criterion 2.4.11: Focus Not Obscured (Minimum), Understanding WCAG 2.2 (Level AA, sticky headers and footers, cookie banners, scroll padding, and the stricter 2.4.12 at AAA), https://www.w3.org/WAI/WCAG22/Understanding/focus-not-obscured-minimum.html

  8. 8.

    W3C Web Accessibility Initiative, Understanding Success Criterion 2.4.13: Focus Appearance, Understanding WCAG 2.2 (Level AAA, an area at least as large as a 2 CSS pixel thick perimeter and a 3:1 contrast between focused and unfocused states), https://www.w3.org/WAI/WCAG22/Understanding/focus-appearance.html

  9. 9.

    CEN, CENELEC and ETSI, EN 301 549 V3.2.1 (2021 03), Harmonised European Standard, Accessibility requirements for ICT products and services, clause 9 (web), ETSI, 2021, https://www.etsi.org/deliver/etsi_en/301500_301599/301549/03.02.01_60/en_301549v030201p.pdf

  10. 10.

    MDN Web Docs, tabindex, Mozilla (meaning of negative, zero and positive values, the advice to use only 0 and minus 1, and the warning against making a div act as a button), https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/tabindex

  11. 11.

    MDN Web Docs, :focus-visible, Mozilla (when the pseudo class matches, and the accessibility note that the focus indicator needs at least 3:1 under WCAG 1.4.11), https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible

  12. 12.

    Government Digital Service, Skip link, GOV.UK Design System (placement immediately after the opening body tag, visually hidden until focused, link text Skip to main content), https://design-system.service.gov.uk/components/skip-link/

  13. 13.

    W3C Web Accessibility Initiative, Example Disclosure Navigation Menu, ARIA Authoring Practices Guide (button with aria-expanded and aria-controls, Escape closes and returns focus to the button, why the menu role is not used), https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/examples/disclosure-navigation/

  14. 14.

    W3C Web Accessibility Initiative, Dialog (Modal) Pattern, ARIA Authoring Practices Guide (focus moves into the dialog on open, Tab and Shift Tab stay inside, Escape closes, focus returns to the invoking element), https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/

  15. 15.

    MDN Web Docs, The Dialog element, Mozilla (showModal makes the rest of the page inert, Escape dismisses a modal dialog, initial focus and the autofocus attribute, and an explicit close button as the most robust way to close), https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/dialog

  16. 16.

    W3C, Using ARIA, Discontinued Draft, 24 February 2026 (the first, second and fourth rules of ARIA use; readers are referred to the ARIA Authoring Practices Guide), https://www.w3.org/TR/using-aria/

  17. 17.

    Playwright, Keyboard (keyboard.press) and LocatorAssertions (toBeFocused), Playwright documentation, Microsoft, https://playwright.dev/docs/api/class-keyboard and https://playwright.dev/docs/api/class-locatorassertions

  18. 18.

    Minister for Children, Equality, Disability, Integration and Youth, S.I. No. 636/2023, European Union (Accessibility Requirements of Products and Services) Regulations 2023, electronic Irish Statute Book, 2023, https://www.irishstatutebook.ie/eli/2023/si/636/made/en/print

  19. 19.

    European Parliament and Council, Directive (EU) 2019/882 of 17 April 2019 on the accessibility requirements for products and services (European Accessibility Act), EUR Lex, 2019, https://eur-lex.europa.eu/legal-content/EN/TXT/HTML/?uri=CELEX:32019L0882

  20. 20.

    Competition and Consumer Protection Commission, European Accessibility Act becomes law in Ireland on 28 June 2025, press release, 26 June 2025 (e-commerce among the covered services, the CCPC as compliance authority for e-commerce), https://www.ccpc.ie/news-and-media/news/article/2025/06/26/european-accessibility-act-becomes-law-in-ireland-on-28-june-2025/

  21. 21.

    Oireachtas, Equal Status Act 2000, section 4, Discrimination on ground of disability, electronic Irish Statute Book, https://www.irishstatutebook.ie/eli/2000/act/8/section/4/enacted/en/html