Links With Event Handlers and No Href Attribute
WCAG Focus: WCAG 2.1.1 (A), 4.1.2 (A)
Developers frequently write <a onclick=”openTab()”>Read FAQ</a> omitting the href attribute so the browser does not jump to the top of the page. Unfortunately, in HTML, an <a> tag without an href is not keyboard focusable and loses its link role in the accessibility tree.
Why This Pattern Violates WCAG
WCAG 2.1.1 Keyboard (Level A) fails because browsers exclude <a> tags lacking href from the sequential Tab order.
WCAG 4.1.2 Name, Role, Value (Level A) fails because assistive technologies do not expose the element as an interactive link or button.
Code Comparison
Inaccessible Anchor Missing Href
<a onclick="openModal()" class="btn">Open Offer</a>
Compliant Button for Actions (or Href for Links)
<button type="button" onclick="openModal()" class="btn">Open Offer</button>
How to Fix It in WordPress
- Use <button type=”button”> whenever clicking triggers an in-page script, modal, or tab switch.
- If the element genuinely navigates to a URL or anchor, include a valid href=”…” attribute.
Finding This Issue Automatically
Themes and third-party scripts often omit href on JavaScript-driven anchor tags. The WP ADA Compliance Check plugin flags anchor tags missing href attributes and can automatically fix the issue by adding role, tabindex, and keyboard event handlers where event handlers emulate links.
Subscribe
Subscribe to receive daily Web Accessibility - Did you know? articles in your inbox.

