axe-core aria-roles error invalid role value
Fixes the axe-core aria-roles error by replacing invalid or misspelled role values with real ARIA roles. Use it when axe flags a role that does not exist in the spec. Not for valid roles used on the wrong element, which is the aria-allowed-role rule.
axe-core aria-roles error invalid role value - how to fix it
TL;DR
Replace the invalid role with a real ARIA role (or remove it and let the element's native semantics work). Axe flags roles that do not exist in the spec, including typos like buton. One line of why: an unknown role wipes out the element's implicit semantics and assistive tech falls back to generic, so the control becomes a mystery.
The error, verbatim
{
"id": "aria-roles",
"impact": "critical",
"help": "ARIA roles must be valid",
"nodes": [
{ "target": [".nav-toggle"], "failureSummary": "Fix any of the following: ARIA role buton is not valid" }
]
}Fix it step by step
Step 1: Reproduce on one page
npx @axe-core/cli https://example.com --rules aria-roles --save axe-roles.jsonExpected: Violations array contains aria-roles with the invalid role named per node.
Step 2: Extract the invalid roles
node -e "const r=require('./axe-roles.json'); r.violations[0].nodes.forEach(function(n){console.log(n.target.join(' '), '-', n.failureSummary.match(/role (\S+) is not valid/)[1])})"Expected: Lists each selector with its bogus role value.
Step 3: Find them in source
rg -n 'role=' src --glob '*.{jsx,tsx,vue,html}' | head -30Expected: Shows every hardcoded role so you can spot the typos and invented roles.
Step 4: Fix the roles and re-scan
npx @axe-core/cli https://example.com --rules aria-rolesExpected: Exit code 0, 0 violations. The control now exposes a real role to assistive tech.
Step 5: Gate the rule in CI
npx @axe-core/cli https://example.com --exit | tail -3Expected: Non-zero exit while any violation remains; add this command to CI so the fix never regresses.
When to use this skill
- Your axe-core report lists this exact rule id under violations
- You are clearing automated WCAG 2.1 AA failures before a release or audit
- A CI a11y gate (pa11y-ci, lighthouse CI, cypress-axe) is red because of this rule
When NOT to use this skill
- The issue only shows up in manual screen-reader testing and axe reports zero violations for the rule
- You are doing a full manual WCAG audit, this skill covers the single automated rule only
- The page is a third-party embed you cannot edit, flag it to the vendor instead
Compatibility
axe-core 4.8+ (rule aria-roles, WCAG 4.1.2). Same rule in axe DevTools and pa11y. Pin the tool version in the lockfile so scans stay reproducible across machines.
Variant phrasings
aria role buton is not valid
The failureSummary wording for a typo, fix is one character.
axe invalid aria role value
General phrasing, covers invented roles like toggle or dropdown.
axe DevTools flags the same rule
The browser extension runs the same rule engine; fix once and it clears in every runner.
Why it happens
Role values are free-form strings in HTML, so a typo like buton or an invented role like dropdown passes every build tool and only fails at scan time. Abstract roles (like widget or command) are also invalid on elements even though they exist in the spec. Axe validates against the concrete role list, so anything misspelled, abstract, or made up fails. The same violation usually repeats on every page built from the same template, so fix the component or template once instead of patching pages. After the fix, re-scan the whole site, not just the one page, to confirm the template-level change cleared them all.
Edge cases
- Abstract roles (widget, composite, landmark, input) exist in the spec but are never valid on an element, use a concrete subclass.
- If the element already has the right native semantics (button, nav, main), delete the role attribute instead of fixing it.
- role presentation and role none are valid and equivalent, pick one spelling per codebase for consistency.
- Fix every instance of the rule before moving on; a half-fixed rule across templates re-fails the next full scan.
Provenance
Resolved from the public thread: https://vectle.com/posts/pstllBlz4Dpsq7xmlPFbvtIQ
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.