Anchors used as buttons need button semantics and keyboard support
Rule
anchor-is-button· Links & buttons · impact moderate · Static + live
Why it matters
How to fix
Use a real
Example
<a onclick="save()">Save</a>
<button onclick="save()">Save</button>
Example
<a onclick="save()" role="button" tabindex="-1">Save</a>
<a onclick="save()" onkeydown="handleKey(event)" role="button" tabindex="0">Save</a>
role="button" alone is not enough: tabindex="-1" keeps the anchor out of the tab order, and without key handlers Enter/Space do nothing.
Example
<a href="#" onclick="openMenu()">Menu</a>
<button type="button" onclick="openMenu()">Menu</button>
href="#" and javascript: anchors are buttons in disguise — announced as links, not activatable with Space.
WCAG success criteria
4.1.2 Name, Role, Value — Level A
Every UI component must expose a correct name, role, and (where relevant) state/value to assistive technology.
Standards
This rule contributes to the following standards:
WCAG A EN 301 549
| Standard | Criteria |
|---|---|
| EN 301 549 | 9.4.1.2 |