useAltText (JavaScript)
Summary
Section titled “Summary”- Rule available since:
v1.0.0 - Diagnostic Category:
lint/a11y/useAltText - This rule is recommended, meaning it is enabled by default.
- This rule doesn’t have a fix.
- The default severity of this rule is error.
- Sources:
- Same as
jsx-a11y/alt-text - Inspired from
@html-eslint/require-img-alt
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "a11y": { "useAltText": "error" } } }}Description
Section titled “Description”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 screen reader users in order for them to understand the content’s purpose on the page.
This rule checks for alternative text on the following elements: <img>, <area>, <input type="image">, and <object>.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<img src="image.png" />code-block.jsx:1:1 lint/a11y/useAltText ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide a text alternative through the alt, aria-label or aria-labelledby attribute
> 1 │ <img src="image.png" />
│ ^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Meaningful alternative text on elements helps users relying on screen readers to understand content's purpose within a page.
ℹ If the content is decorative, redundant, or obscured, consider hiding it from assistive technologies with the aria-hidden attribute.
<input type="image" src="image.png" />code-block.jsx:1:1 lint/a11y/useAltText ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide a text alternative through the alt, aria-label or aria-labelledby attribute
> 1 │ <input type="image" src="image.png" />
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Meaningful alternative text on elements helps users relying on screen readers to understand content's purpose within a page.
ℹ If the content is decorative, redundant, or obscured, consider hiding it from assistive technologies with the aria-hidden attribute.
<img src="image.png" alt="image alt" /><input type="image" src="image.png" alt="alt text" /><input type="image" src="image.png" aria-label="alt text" /><input type="image" src="image.png" aria-labelledby="someId" />Accessibility guidelines
Section titled “Accessibility guidelines”Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.