Skip to content
easeweb
Search topics

Buttons announced as links that Space can't press

A pill that opens a form is built on a link with href="#", so a screen reader calls it a link and Space scrolls the page instead of pressing it.

WCAG 2.2
SC 4.1.2A
Required by
Section 508 · EN 301 549 (EU)
Broken <a href="#" class="pill">
The accessibility problem illustrated: No vision:Where will this link take me?
01

The problem

Screen reader users are told a control is a link that will take them somewhere, when it opens a form, and keyboard users who press Space scroll the page instead

02

Try it

Press Tab to reach “Email me when it’s back”, then press Space. Then try Enter

Does Space open the form, or does the page scroll? The panel shows what a screen reader calls the pill: a link or a button.

Broken Can you fix this?

BrokenA link that points nowhere, drawn as a pill

Linen tote

$48

Sold out

Email me when it’s back

About this bag

A roomy tote in washed linen that softens with every wash. It folds flat into its own pocket, so it goes everywhere.

  • Washed linen, 40 by 38 cm
  • Inside pocket with a zip
  • Long handles that fit over a shoulder

Delivery and returns

Free delivery on orders over $60. Returns are free within 30 days, in the original packaging.

Care

Machine wash cold and hang to dry. A warm iron brings back the crisp look.

Email me when it’s back

We’ll send one email when the linen tote is back in stock.

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Make the pill read as a button, and press with Space

Before
BrokenA link that points nowhere, drawn as a pill
<p class="stock">Sold out</p><a href="#" class="pill notify">  Email me when it's back</a><dialog id="notify" aria-labelledby="notify-title">  …</dialog>
What is wrong2 points
  • A screen reader announces a link, so people expect to leave the page. The a element makes the pill a link, and only the script makes it act as a button.
  • Pressing Space scrolls the page instead of opening the form. On a link, Space is the key that scrolls the page, and only Enter clicks it.

The same goes for href="javascript:void(0)" and for a link whose address is real but whose script always cancels it.

After

A button

<p class="stock">Sold out</p><button type="button" class="pill notify">  Email me when it's back</button><dialog id="notify" aria-labelledby="notify-title">  …</dialog>
How it is fixed4 steps
  1. Replace the a with a button. It is announced as a button, and the browser runs its click handler for Enter and for Space, so no key handling is needed and the page never scrolls.
  2. Give it type="button", which keeps it from sending a form it sits in.
  3. Drop preventDefault() from the click handler, since there is no link to cancel.
  4. In the CSS, take away the browser's border and grey face and set the font, so the pill looks as it did.

This fixes the Before and passes 4.1.2.

Why this fix: Use native HTML first

The patch that is not a fix
<a href="#" role="button" class="pill notify">  Email me when it's back</a>

Easily confused
04

Verify the fix

4 checks, no mouse.

Test with: Keyboard, Screen reader

0 of 4 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the shared button or link component changes.

Limits

This guide covers a link that does a button's job. The reverse, a button that only takes people to another page, is the same topic seen from the other side, and is meant for a later guide: it is announced as a button, and it can't be opened in a new tab or found in the list of links. For a div or span with a click handler and no role at all, see div buttons that can't be reached with Tab. Links that filter or sort the page in place belong to the topic on links that update the page, and a button with no words to 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.

See the service