← Back to HTML & CSS, page 2

html-css-0024 · Easy fresher

How do you write good alt text for images?

The alt attribute is the text equivalent of an image. Informative images get a short description of what matters, functional images (inside links or buttons) describe the action, and decorative images get an empty alt. Complex images such as charts need a short alt plus full data in nearby text. Never leave alt out.

Full answer

The alt attribute gives an image a text equivalent. Screen readers read it. The browser shows it when the image fails to load. Search engines use it to understand the image.

What to write depends on the job of the image.

  • Informative image: say what a person would learn from seeing it. Keep it short, usually one sentence.
  • Functional image (an image inside a link or button): describe the action, not the picture. A magnifying glass inside a button is "Search".
  • Decorative image: use an empty alt="". Screen readers then skip it. Better still, put purely decorative pictures in CSS as backgrounds.
  • Complex image such as a chart: give a short alt with the main point and put the full data in text or a table nearby.

Do not start with "image of" or "picture of". The screen reader already says it is an image. Do not stuff keywords.

The first image is announced with its meaning. The logo link is announced as "Greenfield College home, link". The divider is skipped. The last image has no alt at all, which is the worst case: many screen readers read out the file name instead.

A useful test: if the image disappeared, what text would you put in its place so the reader still gets the same information? That text is the alt.

html
<img src="results.png" width="500" height="300"
     alt="Bar chart: pass rate rose from 62% in 2023 to 81% in 2025">

<a href="/home"><img src="logo.png" width="120" height="40" alt="Greenfield College home"></a>

<img src="divider.png" width="400" height="10" alt="">

<img src="photo.png" width="300" height="200">

Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.

Key points

  • Informative image: describe the information it carries.
  • Functional image: describe the action or destination.
  • Decorative image: alt="" so screen readers skip it.
  • Complex image: short alt plus a long description in text.
  • Do not start with image of, and do not stuff keywords.

Common mistakes

  • repeating the visible caption in the alt text, so screen reader users hear it twice. Alt should add what the caption does not say.
  • writing alt="image" or the file name. This adds noise and no information.

Follow-ups

  • how long should alt text be?
  • How is alt text different from a figcaption?
  • What happens in a screen reader when alt is missing entirely?

Tips

  • Always include the alt attribute, even when it is empty. A missing alt is an error. An empty alt is a deliberate choice.
  • Use the 'what text would replace this image' test and say it in the answer.
  • Give three examples: a chart, a logo link and a divider.