prefer-native-element
What it does
Section titled “What it does”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">).
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...<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>...Configuration
Section titled “Configuration”angular: lint: rules: prefer-native-element: warn # off (default), warn, errorhtml: lint: rules: prefer-native-element: warn # off (default), warn, errorsvelte: lint: rules: prefer-native-element: warn # off (default), warn, errorvue: lint: rules: prefer-native-element: warn # off (default), warn, errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”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 |