Skip to main content
🎉 A11y Issue Detection Agent is now live! Detect accessibility issues like a WCAG expert with AI. Try now!
No Result Found
Connect and get help from 7,000+ developers on our Discord community. Ask the CommunityAsk the Community

role-img-alt

Rule Severity : Serious

Description

The role-img-alt rule ensures that elements with role="img" have an accessible name. The role="img" attribute is used when a non-<img> element, such as an SVG, a group of icons, or a CSS-rendered image, is intended to convey visual information. Without an accessible name, screen reader users receive no information about the visual content, making it completely invisible to them.

This rule meets WCAG requirements by:

  1. Providing Text Alternatives (WCAG 1.1.1 Non-text Content): It ensures that all non-text content that conveys information has a text alternative that serves an equivalent purpose, allowing users who cannot see the visual content to receive the same information through assistive technologies.
  2. Programmatic Name Determination (WCAG 4.1.2 Name, Role, Value): It ensures that the name of every element used as an image can be programmatically determined by assistive technologies.

To comply with this rule, every element with role="img" must have an accessible name provided via aria-label or aria-labelledby.

Examples

This example shows a <div> with role="img" wrapping an SVG icon but with no accessible name. Screen readers skip this element entirely or announce it without any descriptive information.

Incorrect Sample
Copy icon Copy

Here, aria-label is added to the element with role="img", giving screen reader users a meaningful description of the visual content.

Correct Sample
Copy icon Copy

How to fix?

To fix violations of the role-img-alt rule, follow these steps:

  • Add an aria-label attribute directly on the element with role="img", with a concise description of what the image conveys.

  • Alternatively, use aria-labelledby to reference a visible element on the page that already describes the image, such as a nearby caption or heading.

  • If the image is purely decorative and conveys no information, use role="presentation" instead of role="img" to indicate that assistive technologies should ignore it.

  • Ensure the accessible name describes the meaningful content or purpose of the image, not just “image” or “icon”, so users receive the same information as sighted users.

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