Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a11y alt attribute explainer to html img element #36067

Merged
merged 8 commits into from
Oct 16, 2024
6 changes: 5 additions & 1 deletion files/en-us/web/html/element/img/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,13 @@ An `alt` attribute's value should provide a clear and concise text replacement f
#### Do

```html example-good
<img alt="A Rockhopper Penguin is standing on a beach." src="penguin.jpg" />
<img alt="A Rockhopper Penguin on a beach." src="penguin.jpg" />
```

In terms of accessibility, if you prepend the phrase "Something I saw on my travels:" to the examples above, a screen reader could read the _Don't_ example as "Something I saw on my travels: image", which does not convey the same meaning a sighted person might get combining the text with what they see in the image.
JohannesBeranek marked this conversation as resolved.
Show resolved Hide resolved

For images used to trigger an action, like inside an `<a>` tag or a `<button>` tag, consider using the triggered action as `alt` attribute value (like `alt="next page"` instead of `alt="arrow right"`), optionally adding a description to a `title` attribute, which might be read by screen readers upon user request.
JohannesBeranek marked this conversation as resolved.
Show resolved Hide resolved

When an `alt` attribute is not present on an image, some screen readers may announce the image's file name instead. This can be a confusing experience if the file name isn't representative of the image's contents.

- [An alt Decision Tree • Images • WAI Web Accessibility Tutorials](https://www.w3.org/WAI/tutorials/images/decision-tree/)
Expand Down