Search topics
Div buttons that can't be reached with Tab
A Save control built from a div with a click handler takes no Tab stop and ignores Enter and Space, and role="button" on its own doesn't change the keys.
<div> The problem
Keyboard users cannot save their work, and screen reader users are not told there is a button
A settings screen has a Display name field and a dark green "Save changes" control under it, drawn as a button. Clicking it saves the form. Pressing Tab moves from the last field straight past it to the Help link in the footer, so a keyboard user can fill in the form and never save it. A screen reader user reading down the page hears "Save changes" as plain text, with no role to say it is a button.
A common repair adds role="button" and tabindex="0" to the same div. Tab now stops on Save, and a screen reader says "Save changes, button". The keyboard user presses Enter, then Space, and nothing saves. Space scrolls the page instead. The control now promises to be a button and still doesn't act like one.
Success Criterion 2.1.1 Keyboard asks that everything a pointer can do, a keyboard can do too. The control is a div with a click handler, the pattern of failure F54: a function only a pointer can reach. A div takes no focus, so Tab never lands on it. And the browser presses only certain elements from the keyboard: Enter and Space click a native button, and Enter follows a link. Nothing turns a key into a click on a div, so the handler never runs.
Success Criterion 4.1.2 Name, Role, Value asks that assistive technology can tell what a control is. A div has no role of its own, and neither its CSS nor its click handler gives it one, so the accessibility tree holds only the text "Save changes". This is failure F59: script makes a div a control without a role.
The second version mends the role and the Tab stop, and still fails 2.1.1. role="button" changes only what is announced, and tabindex="0" only puts the div in the tab order. Neither gives it the button's behaviour, so Enter and Space still reach no handler, and Space keeps its usual job of scrolling the page.
The action works with a mouse, so the gap stays hidden from anyone who tests with one. The second version also passes a quick check with Tab, since focus does stop on Save; only pressing it shows the failure.
2 of 10 groups affected
- No vision (affected)
- Low vision (not affected)
- Colour vision (not affected)
- No hearing (not affected)
- Hard of hearing (not affected)
- No speech (not affected)
- Motor (affected)
- Reach, strength (not affected)
- Cognitive (not affected)
- Seizures (not affected)
- Limited manipulation A keyboard user can't save at all: Tab passes Save by, or, once it has role="button" and tabindex="0", stops on it while Enter and Space do nothing. Voice control users may find nothing to say "click" to either, since the div isn't listed as a control.
- Without vision A screen reader reads the div as plain text, not as a button, and Tab never lands on it, so nothing says Save is a button. With the role added, it is announced as a button, but Enter and Space reach no handler of its own. Some screen readers send their own click, so whether it can be pressed depends on the screen reader and its mode.
EaseWeb's audit reports a div or span with an onclick attribute that Tab never reaches, and an element with role="button" but no tabindex. A click listener added from a script, as React's onClick or Vue's @click add it, leaves nothing in the markup, so a scan of the page sees a styled div and some text. Once role="button" and tabindex="0" are added, nothing reports it: axe sees a focusable button with a name, and no rule presses its keys. Linters such as Svelte's compiler and eslint-plugin-jsx-a11y warn in the source about a click handler with no key handler, and about a role with no tabindex. Adding the role and tabindex clears only some of those warnings, and the one that remains can be silenced with a comment, as a quick fix sometimes does. Only pressing the control with Enter and with Space shows whether it works.
What the checkers report
- axe DevTools
- Buttons must have discernible text
- Lighthouse
- Buttons do not have an accessible name
- WAVE
- Empty button
Try it
Put the mouse aside and save your settings with Tab, Enter and Space
Broken 1: Tab on from Display name. Does focus stop on “Save changes”? The panel shows what a screen reader says when it reads down to it.
Broken 2: Tab on from Display name to “Save changes”, then press Enter, and Space. Focus stops and a screen reader says “button”, but does anything save?
Apply a fix. Tab to “Save changes” and press Enter, then Tab away and back and press Space: each one saves.
Broken Can you fix this?
Reading down to Save changes, a screen reader says:
Save changes
The fix
Let Tab reach Save, and Enter and Space press it
A div that only listens for clicks
<div class="save-control"> Save changes</div><p id="save-status"></p>What is wrong4 points
It looks like a button only to people who can see it and use a pointer.
- A keyboard user can't reach Save: a div is not in the tab order, so Tab passes it by.
- A screen reader user isn't told it is a button: with no role, "Save changes" is read as plain text.
- Enter and Space don't save: on a div, neither key becomes a click.
- Even when it saves, a screen reader user isn't told: the result is written into a plain paragraph, so it is shown but not announced.
The same goes for a span, an icon drawn with <i> or <svg>, a whole product card that opens a quick view, and an a with no href: none of them takes focus or has a role until you give it one.
A native button
<button type="button" class="save-control"> Save changes</button><p id="save-status" role="status"></p>How it is fixed4 steps
- Replace the div with a
button type="button". It is in the tab order and has the button role, and its click handler also runs for Enter and Space, so the script stays as it was and no key handling is needed. - In the CSS, add
font: inherit, since a button doesn't take the page's font on its own. The rest of the div's styles, its border included, now replace the browser's, so the button looks as the div did. - Give it a ring on
:focus-visible. - Add
role="status"to the paragraph the result is written into, so the result is read out.
This fixes both Befores and passes 2.1.1 and 4.1.2. The status region must be in the page before its text changes, or the result may not be announced. A native button can also take the look a custom control is often kept for: the div's own styles carry over, and only the font needs setting.
Why this fix: Use native HTML first
Both pass. Use the native button: it does the same job with less code and nothing to give up, since the browser gives it the Tab stop, the role and both keys, and a disabled state and sending a form come with it. Keep the div with role="button", tabindex="0" and the key handlers only where the element can't be replaced, and test its keys again whenever the code that renders it changes.
A button inside a form submits by default, so choose its type by what the control does.
- Local action:
type="button". - Submission:
type="submit". - Toggle: keep the label stable and expose
aria-pressed.
A control that only takes people to another page is a link rather than a button. Choosing between the two is its own topic, and a real link used for an action has its own guide: buttons announced as links that Space can't press. This guide is about the div that should have been a button. A heading that opens a panel when clicked is the same failure with a state to report as well, covered in accordions that don't say whether a panel is open.
Keep the existing font, padding and shape on the native element. Browsers add their own button styles, so reset what conflicts with your design rather than going back to a div. Keep a border on the button, in the fill colour or transparent, rather than border: 0: a Windows contrast theme replaces background colours and draws borders in a system colour, so the border is what keeps the button's shape there.
To stop the problem returning, make the native button the default in your component library: a shared Button that renders a div or a span puts this failure on every page that uses it. In code review, look for click handlers on div, span, i, svg and a with no href, and for linter warnings about click handlers with no key handler that were silenced rather than fixed: each one is likely a control a keyboard can't use.
Verify the fix
6 checks, no mouse.
Test with: Keyboard, Screen reader, Zoom, Forced colors
Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the shared button component changes.
How screen readers handle role="status"
Limits
This is a starting pattern, not a guarantee for every application. The snippets omit application-specific data handling. Parts of a larger widget that take only clicks have their own guides, since the keys they need differ: carousels that keyboard and screen reader users can't use, toolbars of clickable icons a keyboard can't reach and product photo thumbnails that need a mouse or say nothing. A button that is reached but has no words is covered in icon-only buttons with no accessible name. Test the complete journey with your target assistive technology.
This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.
EaseWeb service
Fixed it? Keep it from coming back.
I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.