Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 38 ยท Colour, Contrast and Media

Images and Alternative Text in Depth

Write good alt text for informative, functional, decorative and complex images. Covers empty alt, SVG, icons, figures with captions, charts and text in images.

An image does not exist for a person who cannot see it, unless you describe it. The alt attribute is that description. Good alt text is not a caption of what the picture looks like. It is what the image is for in this place on this page.

WCAG 1.1.1 Non-text Content (level A) asks that every meaningful non-text item has a text alternative that serves the equivalent purpose. Decorative items must be hidden from assistive technology.

The decision tree

Ask these questions in order.

flowchart TD
  A["Image"] --> B{"Pure decoration or repeated text?"}
  B -- "yes" --> C["Use an empty alt attribute"]
  B -- "no" --> D{"Inside a link or button?"}
  D -- "yes" --> E["alt describes the action or destination"]
  D -- "no" --> F{"Complex data (chart, diagram)?"}
  F -- "yes" --> G["Short alt plus long description nearby"]
  F -- "no" --> H["alt gives the meaning in context"]

Purpose first, appearance second.

Informative images

The image adds information to the content. Write the information, in a sentence or less, without "image of" or "picture of" (the screen reader already announces "graphic" or "image").

HTML
<img src="/samples/sunset.svg" alt="Orange sun setting behind two hills">

The same photo can need different alt text in different places. On a travel blog about hiking, you might say "Hikers cross a ridge at sunset". On a page about photo editing, you might say "Original photo before color correction". Always ask what the reader needs here.

Functional images

When an image is the only content of a link or button, its alt is the link's or button's name. Describe the action or destination, not the picture.

HTML
<a href="/cart"><img src="cart.svg" alt="View cart (3 items)"></a>
<button type="button"><img src="trash.svg" alt="Delete comment"></button>

If the link also has text, the icon is redundant and gets alt="".

Decorative images

Dividers, background flourishes, and icons next to text that already says the same thing should be silent. Use an empty alt (not a missing one!) so assistive tech skips the image. A missing alt makes many screen readers read the file name.

HTML
<img src="divider.svg" alt="">

Better still, use CSS background-image for pure decoration so nothing exists in the HTML.

Informative, functional and decorative

Complex images

Charts, diagrams, maps and infographics hold more than a sentence can say. Give a short alt that names the image and points to the detail, then put the full description in the page.

HTML
<figure>
  <img src="sales-2025.svg" alt="Bar chart of quarterly sales for 2025. Details are in the table below.">
  <figcaption>Quarterly sales, 2025</figcaption>
</figure>
<table>...</table>

Options for the long description: a data table, a nearby paragraph, a linked page, or aria-describedby pointing at a hidden-but-available element. A table is usually best: it serves everyone, including people who want to copy the numbers.

Figures and captions

<figure> with <figcaption> ties an image to a visible caption. The caption is not a substitute for alt: screen readers read both, so do not repeat the same words. Alt says what the image shows; the caption adds context ("Fig. 3, taken in 2019").

SVG and icons

Inline SVG needs a role and a name if it is meaningful, or aria-hidden="true" if it is decorative.

HTML
<!-- Meaningful -->
<svg role="img" aria-labelledby="t1" viewBox="0 0 24 24">
  <title id="t1">Warning</title>
  <path d="M12 2 22 20H2z"/>
</svg>

<!-- Decorative -->
<svg aria-hidden="true" focusable="false" viewBox="0 0 24 24">...</svg>

Icon fonts count as text to some readers: hide them with aria-hidden="true" and add real text (visually hidden if needed) beside them.

Icon button with a hidden text label

Text in images

Avoid putting text in raster images. It does not scale, cannot be restyled, and needs alt text that repeats it exactly. If a logo or screenshot contains text, include that text in the alt (for logos: the company name, not "logo").

Common mistakes

  • "Image of..." or "Photo of...": drop the prefix.
  • Alt like IMG_2043.jpg or "spacer".
  • Huge alt paragraphs. Aim for under about 150 characters; use a long description for more.
  • Missing alt on functional images, which makes links announce the file path.
  • Same alt for every thumbnail in a gallery. Make each distinct.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A decorative flourish should have which alt?

    An empty alt tells assistive technology to skip the image. A missing alt is not the same and may make the file name be read.
  2. 2. An image is the only content of a link to the shopping cart. What should its alt describe?

    The alt becomes the link's accessible name, so it should say what the link does.
  3. 3. What is a good way to handle a detailed bar chart?

    Name the chart in alt and give the numbers in an accessible table or text.
  4. 4. Which attributes hide a decorative inline SVG from screen readers?

    aria-hidden="true" removes it from the accessibility tree; focusable="false" also prevents focus in older Edge/IE.

Summary

  • Alt text expresses the image's purpose in context, not its pixels.
  • Functional images name the action; decorative images get alt="".
  • Complex images get a short alt plus a full description or table.
  • Hide decorative SVG and icon fonts; give meaningful SVG a role and name.

Next: Captions, Transcripts and Audio Description