liveBook · Manning

Alternative text

As explained in Architecting Accessibility

Alternative text is a textual description or equivalent supplied for non-text content so its purpose and information can be conveyed without viewing it.

A screen reader user may encounter every image in a page’s reading order. Describing a decorative banner creates audio clutter; leaving a meaningful icon unnamed can hide information or an action. Alternative text gives non-text content an equivalent that fits its purpose, without making users listen to unnecessary detail. section 3.3

Choose the treatment by asking what the image does here:

  • Decorative: use <img alt="">, or use a CSS background image when appropriate. Do not simply omit alt: some screen readers may announce the filename. For a decorative inline SVG, use aria-hidden="true". section 3.3.1
  • Informative: write a short equivalent for the information the image adds, not an inventory of visual details. If surrounding text already supplies that information, the image may instead be decorative. section 3.3.2
  • Functional: name the action or destination, rather than the pictured object. An image-only Search button can use <img alt="Search">; alternatively, label the button with aria-label="Search" and give its image alt="". Visible button text can supply the name without either. section 3.3.3
  • Complex: give a concise alt value, then provide the full information in adjacent structured text or through a link. A long alt string cannot offer the headings, tables, navigation, or user control that a chart’s full explanation may need. section 3.3.4
  • Interactive image map: describe the whole image’s purpose in its alt, and give each linked <area> its own meaningful alt text. section 3.3.5

A small icon, a different job

Beside a download link, a PDF icon can use alt="PDF File" to communicate the file type. There is no need to announce “Icon of a PDF document.” If the link text already says it is a PDF, consider making the icon decorative instead. section 3.3.2

<figure role="group"> #A
  <img 
    src="poll.png"
    alt="Pie chart of exit poll results. Full details presented below."> #B
  <figcaption> #C
    <h2>Exit poll results</h2>
    <p>In the recent exit polls, we have observed the following outcomes...</p>
    <h3>Sentiment towards leaders</h3>
    <p>The following table presents….</p>
    <table>
      ...
    </table>
  </figcaption>
</figure>

The poll-chart example pairs brief alt text with a nearby, structured description containing headings and a table. The short alternative points readers to the detail rather than squeezing it into one announcement. section 3.3.4

TIP: Test with a screen reader or inspect the accessibility tree to check that decorative images stay silent. Review generated alt text manually: an image description alone may miss the image’s purpose in context. For text-heavy graphics, prefer real text where possible; alt cannot preserve embedded headings and lists or make pictured text respond to font settings. section 3.3.1 section 4.4.4

How Architecting Accessibility covers it

How deep it goes
Works through decorative, informative, functional, complex, and interactive images, including HTML treatments and limits of long alt strings.
Examples
Contrasts a decorative hero image, PDF icon, Search button, poll chart, and linked campus map.
What it assumes
Assumes familiarity with basic HTML elements and attributes while teaching how to distinguish image purposes.
What you can do after
Build it from scratch by assigning purpose-specific alt values and supplying structured text when a short alternative cannot carry the information.
How it connects
Connects accessible names, screen readers, the accessibility tree, semantic HTML, image maps, and structured text descriptions.

Also explained in

Compare how 5 books explain alternative text →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Architecting Accessibility. The section links point to the parts of the book it draws on.