Skip to content

prefer-native-element

Reports a role that a native element already has (main, navigation, button, list, …) when it is on an element that is not that one (<div role="main">, <a role="button">).

A native element comes with the keyboard handling, focus and semantics of its role. An element with a role must be given all of that by script and styles.

To fix, use the native element.

Reported
...
<span role="button" aria-label="x">y</span>
...
<a href="x" aria-label="x">y</a>
<div role="main"></div>
<span role="button"></span>
...
<a href="#" role="button">x</a>
...
<button aria-label="x"></button>
<button><img src="a" alt="x"></button>
...
angular:
lint:
rules:
prefer-native-element: warn # off (default), warn, error
html:
lint:
rules:
prefer-native-element: warn # off (default), warn, error
svelte:
lint:
rules:
prefer-native-element: warn # off (default), warn, error
vue:
lint:
rules:
prefer-native-element: warn # off (default), warn, error

Enabled by the presets: html/html-validate-recommended.

Suppress one line with sudsy-disable-next-line prefer-native-element in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
html-validate prefer-native-element partial 14 roles with a native element; other roles are not checked