Accessibility

a11y/prefer-native-element

Use the native element instead of a role it already provides (button, a href, input, h1–h6, nav, main, ul, li).

minorstaticWCAG 4.1.2 · Afe-a11y-aria

Why

A role changes only what is announced. A div role="button" still needs tabindex, Enter and Space handling, a disabled state and form behaviour written by hand, and each missing piece is a bug for keyboard and screen reader users.

Fix

Swap the element: <button type="button">, <a href>, <input type="checkbox">, <h2>, <nav>, <ul>/<li>. Restyle it with CSS (all: unset or a reset) if the look is the reason for the div. Keep a role only where no native element exists (tablist, switch on a checkbox, img on an svg).

Examples

<!-- bad -->
<div role="button" tabindex="0" onclick="save()">Save</div>
<!-- good -->
<button type="button" onclick="save()">Save</button>

Sources

Facts

Id
a11y/prefer-native-element
Severity
minor
Check
static checked in the source by audit
Applies to
html angular vue svelte astro jsx
WCAG 2.2
4.1.2, level A
Taught by the skill
fe-a11y-aria ARIA, names and live regions
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain a11y/prefer-native-element