Conditional ARIA attributes

Last updated:

How to fix this issue?

Only add ARIA attributes when the element is in a state that requires them. The most common example is aria-expanded, which is only valid on elements that can open or close something:

CORRECT:

aria-expanded on a button that controls a collapsible section

<button aria-expanded="false" aria-controls="menu">Open menu</button>
<ul id="menu" hidden>
  <li>Item 1</li>
</ul>
BAD:

aria-expanded on a plain link that does not control anything collapsible

<a href="/page" aria-expanded="false">Go to page</a>

Another example is aria-checked, which is only valid on checkboxes, radio buttons, and similar roles:

CORRECT:
<div role="checkbox" aria-checked="true">Accept terms</div>
BAD:

aria-checked on a div with no role that supports it

<div aria-checked="true">Some text</div>

Remove any ARIA attribute that does not apply to the current role or state of the element.

Why is this important?

Screen readers read ARIA attributes to describe the state of elements to users. An attribute used outside its valid context produces incorrect or confusing announcements. Users may be told an element is expanded, checked, or selected when it has no such meaning.

Follow the WAI-ARIA specification to check which attributes are valid for each role and under which conditions they apply.

More info:

WCAG 4.1.2 Name, Role, Value.

Rule info

Standard

WCAG A SC 4.1.2

Regulations

EN 301 549 RGAA EAA AODA

User impact

Fix complexity

Was this article helpful?

Checkout the ExcellentWebCheck services

ExcellentWebCheck's goal is to improve the online user experience. The tools of ExcellentWebCheck help to detect and improve usability problems on your website.