Skip to content
easeweb
Search topics

Buttons that work only by touch on touchscreen devices

The page tests for a touchscreen and, when it finds one, listens for touchend in place of click, so a mouse click or the Enter key does nothing.

WCAG 2.2
SC 2.5.6AAA· new in 2.1
Required by
Not required by Section 508 or EN 301 549
Broken 'ontouchstart' in window ? 'touchend' : 'click'
The accessibility problem illustrated: Motor:Why does only a tap open it?
01

The problem

People with a touchscreen laptop or a tablet keyboard can't open Filters with the mouse or the keyboard, and in Chrome and Edge not by voice either.

02

Try it

Open Filters with the mouse, then with Tab and Enter.

This demo acts as if your device has a touchscreen, as Chrome and Edge do on a touchscreen laptop. If yours has one, tap Filters too.

Broken Can you fix this?

BrokenTouchend when a touchscreen is found

Mugs 12 products

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Listen for click on every device.

Before
BrokenTouchend when a touchscreen is found
<button type="button" class="filters-toggle" aria-expanded="false" aria-controls="filters">  Filters</button><form id="filters" class="filters" hidden>  …</form>
What is wrong3 points
  • On a touchscreen laptop, or a tablet with a keyboard, 'ontouchstart' in window is true, so the button listens for touchend alone.
  • A mouse click never sends touchend, so clicking Filters does nothing.
  • Enter and Space press the button with a click, so they do nothing either, and in Chrome and Edge neither do a screen reader and voice control.
After
FixClick on every device
<button type="button" class="filters-toggle" aria-expanded="false" aria-controls="filters">  Filters</button><form id="filters" class="filters" hidden>  …</form>
How it is fixed2 steps
  1. Delete the touch test. Nothing on the page decides any more which way of pressing counts.
  2. Listen for the button's own click. A tap fires it as the finger lifts, and so do a mouse click, Enter and Space on the focused button, a screen reader and voice control, so the panel opens whichever the person uses, and they can switch at any time.

This fixes the Before and passes 2.5.6. The tap is no slower than before, as long as the page keeps its <meta name="viewport" content="width=device-width">.

Why this fix: Use native HTML first

04

Verify the fix

4 checks.

Test with: Touch, Mouse, Keyboard, Speech input, 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 menu scripts change.

Limits

This is a starting pattern, not a guarantee for every application. It covers listeners chosen by a touch test. A carousel whose arrows are hidden on touch devices leaves a swipe as the only way, which pinch, drag and tilt gestures with no button covers. Menus that open on hover once a mouse is found, and on-screen keyboards a page forces in place of the real one, can fail the same criterion and need their own checks. Some restrictions are allowed: a touch-typing tutor may insist on the keyboard, because that is what it teaches. Test on the touchscreen laptops and tablets your users actually have.

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