Elements With Pointer Event Handlers Missing Keyboard Event Handlers

Elements With Pointer Event Handlers Missing Keyboard Event Handlers

WCAG Focus: WCAG 2.1.1 (A)

WordPress themes and interactive plugins frequently attach mouse-only handlers such as onclick, onmousedown, or onmouseover to elements without pairing them with keyboard event listeners like onkeydown or onkeypress. Users navigating solely with a keyboard, switch device, or screen reader cannot trigger those interactions.

Why This Pattern Violates WCAG

WCAG 2.1.1 Keyboard (Level A) requires all functionality of the content to be operable through a keyboard interface without requiring specific timings for individual keystrokes.

Pairing mouse-only events with native <button> or <a> elements—or explicit keyboard handlers—ensures parity for non-pointer users.

Code Comparison

Inaccessible Mouse-Only Event Handler

<div onclick="toggleDetails()" onmouseover="highlightCard()">View Details</div>

Compliant Native Button With Keyboard & Focus Support

<button type="button" onclick="toggleDetails()">View Details</button>

How to Fix It in WordPress

  • Replace clickable <div> or <span> triggers with native <button type="button"> or <a href="…"> elements whenever possible.
  • Where custom event handlers are required, pair onclick/onmousedown with onkeydown/onkeypress handling Enter and Space, and pair onmouseover with onfocus.

Finding This Issue Automatically

Mouse-only event attributes are easy to overlook when testing exclusively with a trackpad. The WP ADA Compliance Check plugin flags pointer-only handlers during scans and can automatically fix the issue by adding an onkeypress keyboard event handler to elements that include only mouse handlers such as onclick.

WCAG References & Supporting Materials

WCAG Success Criteria

Supporting Documentation & Guides

Subscribe

Subscribe to receive daily Web Accessibility - Did you know? articles in your inbox.

Cart Accessibility Tools
hide