Alt text: what an image says when nobody can see it
AccessibilityWhich image needs which alt text, when the field has to stay empty and why the same text is right for screen readers and for Google.
11 min read
By Timo Wessels Published
Alternative text is the text that takes the place of an image when someone cannot see the image. A screen reader, a program that reads the page aloud, reads it out. It is output on a Braille display or shown when the image does not load. It belongs in the alt attribute of the image.
What goes in does not depend on the image but on what it does on the page:
- An image that carries information gets a short description of that information.
- A linked image gets the link destination.
- A purely decorative image gets an empty
alt="".
The most common mistake is not the missing text but the wrong one: writing something in everywhere.
The most important points first:
- An image that carries information gets a short description of that information.
- An image that is a link describes the link destination.
- A purely decorative image gets an empty
alt="".
What it is about
The alt attribute stands directly in the image tag:
<img src="dog.jpg" alt="Small dog with its own fur falling over one eye">
Success criterion 1.1.1 of the WCAG (the international guidelines for accessible websites), Level A, requires it: all non-text content needs a text alternative that serves the same purpose. Pure decoration must be built in so that assistive technology can skip it. The W3C names who benefits from text alternatives:
- Screen reader users, to whom the text is read aloud or output as Braille.
- Users of speech input, who steer an image button or an image as a link with a voice command.
- Mobile users, who switch images off, especially when abroad, to save data.
- Search engines, because images become searchable.
The text alternative is determined by the author, depending on usage, context and content. That is how the W3C itself puts it. There is no text that belongs to an image. There is only one that belongs to an image at a particular place.
The decision before the text
Before you write, classify the image. In its images tutorial the W3C distinguishes, among others:
| Type | Example | What goes in the alt |
|---|---|---|
| Informative | Product photo, portrait, simple graphic | short description of the information |
| Decorative | Background pattern, divider line, mood image | nothing: alt="" |
| Functional | Logo as a link, magnifier as search button | the destination or action, not the look |
| Image with text | Graphic with a slogan | the text from the image |
| Complex | Diagram, infographic, blueprint | short text plus detailed description on the page |
The W3C decision tree
The W3C has a decision tree for this. It is more practical than any rule of thumb. Go through the questions in this order:
1. Does the image contain text?
- The text is also there next to it as real text →
alt="" - The text is only a visual effect →
alt="" - The text has a function, for example as an icon → describe the function
- The text appears nowhere else → put the text from the image in the
alt
2. Is the image in a link or button whose purpose would be unclear without the image? → describe the link destination or action.
3. Does the image contribute to the meaning of the page?
- Simple graphic or photo → brief description of the meaning
- Diagram or complex information → also output the information on the page
- Only repeats what stands next to it as text →
alt=""
4. Is the image purely decorative or not intended for users? → alt=""
If you are still unsure after that, the four questions from WCAG technique G94 help:
- Why is this image here?
- What information does it present?
- What purpose does it fulfil?
- If I could not use the image: with which words would I convey the same function or information?
The fourth question is the most useful. It takes you away from describing and towards translating. According to the WCAG, the technique is only an example of how to meet the guidelines, not a requirement.
What a good alternative text looks like
Brief but exact. WebAIM puts it like this: content and function as succinctly as possible, without sacrificing accuracy. A few words are usually enough, rarely a short sentence or two. There is no fixed character limit.
Without “image of” or “photo of”. WebAIM gives “Image of Ellen Ochoa, Astronaut” as an example of a description that redundantly describes the image as an image. MDN writes: the text should not describe the presence of the image or the file name.
Without embellishment. “Two tradespeople installing a window” is better than “Motivated team at work on a high-quality window”. Describe what can be seen and what it means, no advertising. That is my assessment.
For linked images: the destination, not the look. The W3C writes that the text should convey the action that is triggered. Its own example: the W3C logo that leads to the home page has the alternative text “W3C home”. MDN gives a similar example: “next page” instead of “arrow right”.
Search terms only where they fit naturally. More on this in the next section.
What Google does with the alternative text
Google uses the alternative text together with computer vision and the content of the page to understand what an image shows. For a linked image it also serves as the anchor text of the link.
Google explicitly warns against stuffing the alt with search terms: it worsens the user experience and may cause the site to be seen as spam. Google’s own example shows the gradation:
- bad: a long string of dog breeds and “puppy food cheap dogfood”
- better:
alt="puppy" - best:
alt="Dalmatian puppy playing fetch"
Two more points from the same guide: short, descriptive file names help (my-new-black-kitten.jpg instead of IMG00023.JPG), and images included by CSS as a background are not indexed by Google. For decoration that does not matter. For a product photo it does.
The good news: what is right for screen readers is also right for Google. You do not write two versions.
When the field must stay empty
This is the half that is regularly done wrong. A decorative image gets the alt attribute, but without content:
<img src="pattern.jpg" alt="">
Two quotation marks directly after one another. That is the instruction to assistive technology: skip it. The W3C gives this reason: text values for such images would only fill the screen reader output with noise or distract users.
Leaving alt out entirely is something else. MDN writes: if the attribute is missing, some screen readers read out the file name. The W3C says the same for functional images: missing or empty values make the screen reader announce the file name or the address. IMG-20240517-final-v2.jpg is worse than any description.
A title attribute does not belong on decorative images either. WCAG technique H67 is literally titled: null alt text and no title attribute on images that assistive technology should ignore.
CSS is even cleaner. The W3C writes: where possible, decorative images should be provided as CSS background images. WebAIM also names CSS images for decoration. Then they are not in the content at all. Where that is not possible, for example because the page builder only knows image elements, the empty alt is the right way.
The special case: image in a link.
- The link already has a text →
alt="". The screen reader reads the link text, the image stays silent. - The link has no text → the
altmust carry the link. The logo that leads to the home page getsalt="Musterbetrieb home page", notalt="Logo".
The second case is the most common real mistake in this area. That is my experience. The W3C notes for an image as the only content of a link that the image then carries the function of the link. Without alternative text the user hears the file name or nothing.
The title attribute is no solution
title creates a small box that usually appears when the mouse rests on the image. MDN writes clearly: do not assume anyone will ever see it. Whoever uses only the keyboard or a touchscreen does not see it.
It follows:
titleis no substitute foralt.titleshould not repeat the alternative text. Some screen readers otherwise read the same text twice.- For a caption there are
<figure>and<figcaption>, nottitle. - What matters belongs visibly on the page.
When one sentence is not enough
With diagrams, infographics and blueprints the alternative text is overstretched. A bar chart with twelve values cannot be translated into one sentence.
The former longdesc attribute is listed as obsolete in the HTML standard. The W3C today describes these ways:
- Output the information on the page: a paragraph below the diagram that summarises the message, or a table with the values.
- A link directly next to the image to a page or section with the detailed description. The link text must make the destination clear. With
<figure>and<figcaption>, image and link can be held together. This way is supported by all browsers and assistive technologies, and the description is also available to search engines. aria-describedbypointing to a text elsewhere on the page. The W3C points to a limit: the linked text is read out as a single paragraph, headings and tables in it are lost.
The first way is almost always the best. It hides nothing, helps everyone who does not understand the diagram at once, and makes the numbers findable as real text. That is my assessment.
How to check it yourself
Switch images off. In the browser settings, loading images can be turned off. Reload the page: what you read now is roughly what a screen reader user hears.
The WAVE extension. The free tool from WebAIM for Chrome, Firefox and Edge checks a page directly in the browser for accessibility problems. A good first pass.
The logo test. Open the source of your home page with Ctrl+U and find the logo in the header. If its alt says “Logo” or nothing at all, although it links to the home page, you have your first finding.
Have it read aloud. NVDA is a free screen reader for Windows. Go through your home page with it once by keyboard. The first minutes are confusing, after that you hear at once which images are labelled unusably.
The WordPress media library, with a catch. In the media library every image has a field for alternative text. But this text is copied when inserted into the post. The post then stores it itself. If you change it later in the media library, the already inserted image keeps the old text. That also has a good reason: the same image can have different jobs in two places. So check and correct the text where the image stands, in the block.
What you can do
- Start with the linked images. Logo, teaser tiles, image links in overviews. There a wrong alternative text makes a link unusable. That weighs more than an undescribed mood image.
- Then the information graphics. Diagrams get a short text plus the detailed message on the page.
- Then the informative photos: short, exact, without “image of” and without keyword chains.
- Finally set the decorative images to an empty
altor move them into CSS. - Check with WAVE and once with NVDA.
On AI-generated suggestions: tools that describe an image automatically are a usable starting point. But they describe what can be seen, not what job the image has at exactly this place. Whether an image is decorative or a link, the tool does not know. Reading and shortening is mandatory. That is my assessment.
And a correction of expectations: alternative texts are not a project you finish once. Every new image needs the decision again. If you or your staff maintain content, it belongs in the routine, at insertion and not some time later.
Sources
- W3C WAI, Images Tutorial — image types, who benefits from text alternatives, the text depends on usage and context: w3.org(external site: w3.org)
- W3C WAI, An alt Decision Tree — the questions and results of the decision tree: w3.org(external site: w3.org)
- W3C WAI, Decorative Images — empty
alt, CSS background, technique H67: w3.org(external site: w3.org) - W3C WAI, Functional Images — action instead of look, the example “W3C home”, file name for a missing value: w3.org(external site: w3.org)
- W3C WAI, Complex Images — description on the page, link,
figure,aria-describedbyand its limit: w3.org(external site: w3.org) - W3C, Understanding WCAG 2.2: Non-text Content — success criterion 1.1.1, Level A, handling of decoration: w3.org(external site: w3.org)
- W3C, Technique G94: Providing short text alternative for non-text content — the four questions for short text alternatives: w3.org(external site: w3.org)
- WHATWG, HTML Standard: Obsolete features —
longdesconimgis obsolete: html.spec.whatwg.org(external site: html.spec.whatwg.org) - MDN, The Image Embed element —
titleas tooltip, not for keyboard and touch, no substitute foralt, missingaltand file name, emptyalt: developer.mozilla.org(external site: developer.mozilla.org) - WebAIM, Alternative Text — brief without loss of accuracy, no “image of”, CSS images for decoration: webaim.org(external site: webaim.org)
- Google Search Central, Google Images best practices — use of alternative text, anchor text, keyword stuffing as possible spam, file names, CSS images not indexed: developers.google.com(external site: developers.google.com)
- WebAIM, WAVE Browser Extensions — free for Chrome, Firefox and Edge: wave.webaim.org(external site: wave.webaim.org)
- NV Access, Download NVDA — free, for Windows 10 and newer: nvaccess.org(external site: nvaccess.org)
- Image Source Control, Fix missing ALT texts in WordPress — media library and post are not synced, the text is taken when inserted: imagesourcecontrol.com(external site: imagesourcecontrol.com)
- Own practice — the order of steps, the logo test, dealing with AI suggestions.