✅ The extends: 'recommended'
property in a configuration file enables this rule.
Enforce that all elements that require alternative text have meaningful information to relay back to the end user. This is a critical component of accessibility for screenreader users in order for them to understand the content's purpose on the page. By default, this rule checks for alternative text on the following elements: <img>
, <area>
, <input type="image">
, and <object>
.
Enforce img
alt attribute does not contain the word image, picture, or photo. Screen readers already announce img
elements as an image. There is no need to use words such as image, photo, and/or picture. The rule will first check if aria-hidden
is true to determine whether to enforce the rule. If the image is hidden, then rule will always succeed.
This rule forbids the following:
An <img>
must have the alt
attribute. It must have either meaningful text, or be an empty string. If it is an empty string, the <img>
element tag must also have role="presentation"
or role="none"
.
The content of an alt
attribute is used to calculate the machine-readable label of an element, whereas the text content is used to produce a label for the element. For this reason, adding a label to an icon can produce a confusing or duplicated label on a control that already has appropriate text content.
If it's not a meaningful image, it should have an empty alt attribute value and have the role of presentation or none.
img
alt attribute does not contain the word image, picture, or photo. Screen readers already announce img
elements as an image. There is no need to use words such as image, photo, logo, spacer, and/or picture.
Numbers are not considered valid alt text, and this rule disallows using only numbers in alt text.
This rule forbids the following:
This rule allows the following:
Add alternative text to all embedded <object>
elements using either inner text, setting the title
prop, or using the aria-label
or aria-labelledby
props.
This rule forbids the following:
This rule allows the following:
All <input type="image">
elements must have a non-empty alt
prop set with a meaningful description of the image or have the aria-label
or aria-labelledby
props set.
This rule forbids the following:
This rule allows the following:
All clickable <area>
elements within an image map have an alt
, aria-label
or aria-labelledby
prop that describes the purpose of the link.
This rule forbids the following:
This rule allows the following:
- WCAG Technique- using alt attributes on img elements
- WCAG Criterion 1.1.1 - Non-text Content
- HTML 5.2 spec - the img element
- Failure of Success Criterion 1.1.1 due to providing a text alternative that is not null (e.g., alt="spacer" or alt="image") for images that should be ignored by assistive technology