Links, images and media with accessible alternatives
Build semantic, accessible and responsive interfaces from a blank page, and explain why each layout and styling decision works.
What you will be able to do
#- Write link text that makes sense out of context.
- Choose between decorative and informative alt text and know when alt is empty.
Overview
#An image always needs an alt attribute, but the value depends on purpose. Decorative images that add no information use alt="" so assistive technology skips them. Informative images describe the information, not the pixels. Functional images, such as an icon inside a link, describe the action. Never omit alt entirely, because then the file name may be announced.
<img src="/chart.png" alt="Revenue rose from 12k in January to 19k in June" />
<img src="/divider.svg" alt="" />
<a href="/cart">
<img src="/cart.svg" alt="View cart" />
</a>
Links and images combine in another trap: an image link whose alt duplicates the visible caption produces a double announcement. When a link wraps an image and text, the image should usually have alt="" and the text should carry the name.
<a href="/invoices/1042">
<img src="/pdf.svg" alt="" />
Invoice 1042 (PDF)
</a>
For video and audio, provide captions and a transcript. The controls attribute exposes native playback controls, and a <track kind="captions"> attaches a caption file. Media that autoplays with sound is hostile to screen reader users and people in shared spaces; do not autoplay audio.
Exercises
#Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.
Exercise 1Debug
This link produces a double announcement: the icon alt and the visible text are both read. Fix it.
starter.html<a href="/invoices/1042"> <img src="/pdf.svg" alt="PDF icon" /> Invoice 1042 </a>Reveal the reference answer
reference.html<a href="/invoices/1042"> <img src="/pdf.svg" alt="" /> Invoice 1042 </a>Authored expected output: The image is decorative (alt="") and the link name comes from the visible text only.
When visible text already names the link, the icon is decorative and should be removed from the accessibility tree with an empty alt.
Common misconceptions
#- Every image needs a descriptive alt, including decorative ones.
- Omitting alt is the same as alt="".
Follow-up practice
#- html-css-05-lists-tables-data
Your progress
#Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.
Verification: authored. Answers and outputs on this page are authored reference material, not executed results.