Skip to main content
No Result Found

accessible-name

Ensure that interactive elements have an accessible name.

Rule Severity : Serious

All user interface elements must have an accessible name.

Accessible names ensure that assistive technologies, like screen readers, can accurately identify and communicate interactive elements to users. Users of assistive technologies can navigate and interact with your website effectively if all interactive elements have accessible names.

You can use the aria-label attribute to describe the purpose of interactive elements. Also, you can use the aria-labelledby attribute to name visible text elements.

Example

In the following example code, the custom element doesn’t have an accessible name although it has an inner text ‘Click Me’. This code breaks the accessible-name rule as assistive technologies like screen readers cannot identify the element accurately.

Incorrect Sample Code
Copy icon Copy

The following sample code corrects the issue in the earlier example by adding an aria-label:

Correct Sample Code - aria-label
Copy icon Copy

You can also solve the issue by using the aria-labelledby attribute as follows:

Correct Sample Code - aria-labelledby
Copy icon Copy

How to fix?

Follow these steps to fix any violations in the accessible-name rule:

  • Use the aria-label attribute on interactive elements to describe its purpose.
  • If a visible label exists, use the aria-labelledby attribute with the element’s id containing the visible text, to describe its purpose.
  • Add a title attribute that describes the element’s purpose.
  • Add inner text to interactive elements whenever possible. If not feasible, like for input elements, label it with a <label> tag and reference it appropriately.
  • Set the role of non-interactive elements as “none” or “presentation”.

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 Check Circle