CSS-19Required
Use the native element first
Use the HTML element made for the job before a div or span with a role. Actions are <button>, navigation is <a href>, lists are <ul> or <ol>, and page regions are header, nav, main and footer.
How to do it
A native element brings its role, keyboard support and state for free. A div with a click handler has none of them, and WCAG 4.1.2 then fails. Add an ARIA role only when no element exists for the pattern, such as a tab list. The markup must also pass Make every page valid HTML. When no element fits and you add ARIA, follow Use ARIA only for what HTML cannot say.
Examples
HTML example
<!-- Avoid -->
<div class="basket-add" role="button" onclick="add()">Add to basket</div>
<!-- Do -->
<button class="basket-add" type="button" data-action="add-to-basket">Add to basket</button>
JSON example
{
"extends": ["html-validate:recommended"],
"rules": {
"prefer-native-element": "error",
"no-redundant-role": "error"
}
}
How to check
A markup linter with the rules prefer-native-element and no-redundant-role reports 0 problems on the built pages. The built HTML has 0 div or span elements with a click handler or role="button".
Sources
Related rules
- APP-3 Build each control once in Web app interface
- WEB-5 Keep the HTML valid in Website
- AXS-18 Use ARIA only for what HTML cannot say in Accessibility
- CSS-29 Lint the built markup for structure in HTML and CSS
- AXS-26 Let find-in-page open hidden text in Accessibility
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/html-css/html-structure-and-reuse/native-elements-first">Agent Wranglers HTML and CSS playbook</a>. In code you write, add a comment next to it with the same link.