Skip to main content

aria-conditional-attr

Use browsers to store the state of a checkbox. Also, do not use attributes that are exclusive to an element in other elements.

Severity: Serious

Description

This rule covers the following accessibility issues:

  • Browsers use a native state (true, false, mixed) for all checkboxes on a webpage. Screen readers and other assistive technologies perform inconsistently if the aria-checked attribute is used while defining checkboxes. This happens when the native state of browsers and the state in aria-checked doesn’t match.

  • The attributes aria-level, aria-setsize, aria-posinset, and aria-expanded are exclusively designed for the treegrid element. Screen readers and other assistive technologies perform inconsistently if a webpage uses these attributes on other elements.

Success criteria

For this accessibility check to pass, your website must adhere to the following rules:

In checkboxes In elements other than treegrid
Do not use the aria-checked attribute. Do not use <tr> elements aria-level, aria-setsize, aria-posinset, and aria-expanded.

Example

In the following example, the aria-checked attribute is used in a checkbox. This breaks the aria-conditional-attr rule.

Incorrect sample - aria-checked
Copy icon Copy snippet

In contrast, the following code snippet doesn’t use the aria-checked attribute in the checkbox element. Hence, it doesn’t break the aria-conditional-attr rule.

Correct sample
Copy icon Copy snippet

Consider the following example in which the attributes aria-level, aria-setsize, aria-posinset, and aria-expanded are used in a grid element. This code snippet breaks the aria-conditional-attr rule as these attributes must be used only on treegrid elements.

Incorrect sample - grid
Copy icon Copy snippet

In contrast, the following code snippet uses the attributes aria-level, aria-setsize, aria-posinset, and aria-expanded in a treegrid element. Hence, this code snippet does not break the aria-conditional-attr rule.

Correct sample - treegrid
Copy icon Copy snippet

How to fix?

You can follow these steps to fix issues if this rule gets flagged:

  • Check if the aria-checked attribute is used in checkboxes. If so, remove the aria-checked attribute or use a different element.

  • Check if the attributes aria-level, aria-setsize, aria-posinset, and aria-expanded are used in an element other than treegrid. If so, either modify the element to treegrid or remove the aria attributes.

Reference

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Download Copy