edubun
English
1 / 19

1 / 6 · Intermediate

Alternative text for images

A decorative swirl and a sales chart both use the img element, but the right alt text for the first is an empty string and for the second is a full sentence.

Jump to the 9 practice questions

You will learn

  • Write alt text that serves the same purpose as the picture
  • Mark decorative images with an empty alt

1Explore

Words for a picture

A photo of a dog needs words when the reader cannot see it. A screen reader turns a page into speech or braille. When it reaches a picture it cannot look at the pixels, so it reads the alt attribute instead. The same text appears when an image fails to load, and it is what a search engine or a text-only browser receives. WCAG 2.2 puts this first of all: success criterion 1.1.1 Non-text Content, at level A, asks that every image, icon or chart that carries information has a text alternative that serves the same purpose.

The list below the preview is what a screen reader announces, in page order. Change an alt and watch the list change.

Your code
<h1>Corner Bakery</h1>
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 60'%3E%3Cellipse cx='60' cy='34' rx='52' ry='22' fill='%23d9a35b'/%3E%3C/svg%3E" alt="Sourdough loaf, sliced" width="120" height="60">
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 60'%3E%3Cellipse cx='60' cy='34' rx='52' ry='22' fill='%23d9a35b'/%3E%3C/svg%3E" alt="" width="120" height="60">
<img src="IMG_4032.jpg" width="120" height="60">
<p>Fresh every morning.</p>
Preview
What a screen reader announces (simplified)

    2Problem

    The first criterion

    Which WCAG 2.2 success criterion covers text alternatives?

    Hint

    It is criterion number 1.1.1.

    Solution

    Answer: 1.1.1 Non-text Content

    1.1.1 is the first success criterion in WCAG, at level A.

    3Problem

    No alt at all

    What can happen when alt is missing altogether?

    Hint

    Look at the third image in the list above.

    Solution

    Answer: Some screen readers read out the file name

    With no alt, a screen reader may fall back to the file name.

    4Explain

    The same purpose

    The key words are "the same purpose". Alt text is not a caption and not a list of everything in the frame. Ask what a sighted reader gets from the picture in this spot, then write that. A photo of a loaf on a bakery's home page might need only "Sourdough loaf, sliced". The same photo in an article about crust colour might need "Sourdough loaf with a dark, almost black crust and an open crumb". Same file, different job, different text.

    5Problem

    Alt text or caption?

    Is alt text the same thing as a caption?

    Hint

    Who sees a caption?

    Solution

    Answer: No, alt replaces the image; a caption is extra visible text

    A caption is seen by everyone; alt stands in for the image itself.

    6Explain

    Three kinds of image

    The W3C images tutorial sorts most pictures into a few groups. Informative images, such as a photo or a simple diagram, get a short description of what they show. Decorative images, such as a divider line or a background texture, get an empty alt, written alt="", which tells assistive technology to skip them. Functional images, such as a logo that links home or a magnifying glass that submits a search, get text that says what happens: "Corner Bakery home" or "Search", not "logo" or "magnifying glass".

    A short version of the W3C alt decision tree. Images of text take the text itself as alt.

    7Problem

    A wavy divider

    A wavy line that only separates two sections should have

    Hint

    It carries no meaning.

    Solution

    Answer: alt=""

    An empty alt marks the image as decorative so it is skipped.

    8Problem

    A search button image

    A magnifying-glass image is the only content of the search button. Best alt?

    Hint

    Name what it does, not what it looks like.

    Solution

    Answer: Search

    For a functional image, name what it does.

    9Explore

    A link that is only a picture

    The first link is named by its alt. The second has no alt, so the listener hears only a file name.

    Your code
    <header>
      <a href="/"><img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 60'%3E%3Cellipse cx='60' cy='34' rx='52' ry='22' fill='%23d9a35b'/%3E%3C/svg%3E" alt="Corner Bakery home" width="60" height="30"></a>
      <a href="/menu"><img src="menu-icon.png" width="60" height="30"></a>
    </header>
    Preview
    What a screen reader announces (simplified)

      10Problem

      A picture of words

      A banner image shows the words "Open 7 am to 6 pm". Its alt should be

      Hint

      The image shows text.

      Solution

      Answer: Open 7 am to 6 pm

      An image of text takes the same words as alt.

      11Explain

      Empty alt or no alt

      Leaving the attribute out is not the same as leaving it empty. With no alt at all, some screen readers fall back to reading the file name, so a listener may hear something like "IMG underscore 4032 dot jpeg". An empty alt is a deliberate choice that says "nothing to see here". For a complex chart, keep the alt short ("Bar chart of monthly sales, described below") and put the numbers in a table or paragraph next to it, where everyone can read them.

      12Problem

      A detailed chart

      Where should the numbers of a detailed chart go?

      Hint

      Keep alt short; put the numbers where everyone can read them.

      Solution

      Answer: In a table or text near the chart

      Keep alt short and give the data where everyone can read it.

      13Explain

      Check your own pages

      You can check your own pages without special software. View the page source and search for <img: every match should have an alt attribute, empty or not. The developer tools in major browsers also include an accessibility panel that shows the name each image ends up with. Reading those names in a row, out of context, is a good test. If a list says "image, image, chart, logo", a screen reader user hears exactly that.

      14Problem

      "Image of"

      Why avoid starting alt with "image of"?

      Hint

      What does the screen reader say before the alt?

      Solution

      Answer: Screen readers already say it is an image

      The role is announced, so the words are heard twice.

      15Problem

      The attribute

      Which attribute holds an image's text alternative?

      Hint

      Three letters.

      Solution

      Answer: alt

      The alt attribute on img supplies the text alternative. A file name does not explain the image’s purpose, and a visible caption is separate page content.

      16Practice

      A chart and a divider

      The chart shows that sales rose each month from January to March. Give it alt text that says so, and mark the wavy divider as decorative with an empty alt.

      Checks
      • chart has a real description
      • divider has alt=""
      Your code
      <h1>First quarter</h1>
      <img class="chart" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 100'%3E%3Crect width='160' height='100' fill='%23fff'/%3E%3Crect x='20' y='60' width='24' height='30' fill='%23c58a3a'/%3E%3Crect x='60' y='40' width='24' height='50' fill='%23c58a3a'/%3E%3Crect x='100' y='15' width='24' height='75' fill='%23c58a3a'/%3E%3Cline x1='10' y1='90' x2='150' y2='90' stroke='%23333' stroke-width='2'/%3E%3C/svg%3E" width="160" height="100">
      <img class="divider" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 10'%3E%3Cpath d='M0 5 Q 15 0 30 5 T 60 5 T 90 5 T 120 5 T 150 5 T 180 5 T 210 5 T 240 5 T 270 5 T 300 5' fill='none' stroke='%23c58a3a' stroke-width='2'/%3E%3C/svg%3E" width="300" height="10">
      <p>Thank you to everyone who ordered.</p>
      Preview
      Hint

      Say what the chart shows; give the divider alt="".

      A solution
      <h1>First quarter</h1>
      <img class="chart" alt="Bar chart: sales rose each month from January to March" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 100'%3E%3Crect width='160' height='100' fill='%23fff'/%3E%3Crect x='20' y='60' width='24' height='30' fill='%23c58a3a'/%3E%3Crect x='60' y='40' width='24' height='50' fill='%23c58a3a'/%3E%3Crect x='100' y='15' width='24' height='75' fill='%23c58a3a'/%3E%3Cline x1='10' y1='90' x2='150' y2='90' stroke='%23333' stroke-width='2'/%3E%3C/svg%3E" width="160" height="100">
      <img class="divider" alt="" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 10'%3E%3Cpath d='M0 5 Q 15 0 30 5 T 60 5 T 90 5 T 120 5 T 150 5 T 180 5 T 210 5 T 240 5 T 270 5 T 300 5' fill='none' stroke='%23c58a3a' stroke-width='2'/%3E%3C/svg%3E" width="300" height="10">
      <p>Thank you to everyone who ordered.</p>

      17Practice

      A linked logo

      The bread logo is the only thing inside a link to the home page. Give the image alt text that says where the link goes, for example "Corner Bakery home".

      Checks
      • logo link has a name
      Your code
      <header>
        <a href="/">
          <img class="logo" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 80'%3E%3Cellipse cx='60' cy='48' rx='52' ry='26' fill='%23d9a35b'/%3E%3Cpath d='M30 40 l12 -10 M55 36 l12 -10 M80 40 l12 -10' stroke='%23fff3dd' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E" width="60" height="40">
        </a>
      </header>
      Preview
      Hint

      Say where the link goes.

      A solution
      <header>
        <a href="/">
          <img class="logo" alt="Corner Bakery home" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 80'%3E%3Cellipse cx='60' cy='48' rx='52' ry='26' fill='%23d9a35b'/%3E%3Cpath d='M30 40 l12 -10 M55 36 l12 -10 M80 40 l12 -10' stroke='%23fff3dd' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E" width="60" height="40">
        </a>
      </header>

      18Explain

      Common mistakes

      Mistake
      <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 60'%3E%3Cellipse cx='60' cy='34' rx='52' ry='22' fill='%23d9a35b'/%3E%3C/svg%3E" alt="Image of a loaf of bread" width="120" height="60">
      Fixed
      <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 60'%3E%3Cellipse cx='60' cy='34' rx='52' ry='22' fill='%23d9a35b'/%3E%3C/svg%3E" alt="Loaf of bread" width="120" height="60">

      A screen reader already says "image", so "image of" is heard twice.

      19

      Summary

      • Alt text gives the purpose of the image in its place on the page.
      • Decorative images get alt="", not a missing attribute.
      • Links and buttons made of an image need alt that names the action.
      • Long data belongs in text or a table next to the image.

      Next unitHeading structure and landmarks
      Full text · The whole lesson as one text

      What alt text is for

      A photo of a dog needs words when the reader cannot see it. A screen reader turns a page into speech or braille. When it reaches a picture it cannot look at the pixels, so it reads the alt attribute instead. The same text appears when an image fails to load, and it is what a search engine or a text-only browser receives. WCAG 2.2 puts this first of all: success criterion 1.1.1 Non-text Content, at level A, asks that every image, icon or chart that carries information has a text alternative that serves the same purpose.

      The key words are "the same purpose". Alt text is not a caption and not a list of everything in the frame. Ask what a sighted reader gets from the picture in this spot, then write that. A photo of a loaf on a bakery's home page might need only "Sourdough loaf, sliced". The same photo in an article about crust colour might need "Sourdough loaf with a dark, almost black crust and an open crumb". Same file, different job, different text.

      A short version of the W3C alt decision tree. Images of text take the text itself as alt.

      Four common cases

      The W3C images tutorial sorts most pictures into a few groups. Informative images, such as a photo or a simple diagram, get a short description of what they show. Decorative images, such as a divider line or a background texture, get an empty alt, written alt="", which tells assistive technology to skip them. Functional images, such as a logo that links home or a magnifying glass that submits a search, get text that says what happens: "Corner Bakery home" or "Search", not "logo" or "magnifying glass". Images of text get the words in the image.

      Leaving the attribute out is not the same as leaving it empty. With no alt at all, some screen readers fall back to reading the file name, so a listener may hear something like "IMG underscore 4032 dot jpeg". An empty alt is a deliberate choice that says "nothing to see here". For a complex chart, keep the alt short ("Bar chart of monthly sales, described below") and put the numbers in a table or paragraph next to it, where everyone can read them.

      Images that are not img elements

      Pictures can also arrive as inline SVG or as CSS background images. A CSS background has no place for alt text at all, so it should be used only for decoration; anything that carries meaning belongs in the HTML. An inline svg that is pure decoration can be hidden with aria-hidden="true", which unit 6 explains. WCAG sets no character limit for alt text, but the W3C tutorial keeps returning to the same advice: be brief and give what matters in this context. If you find yourself writing three sentences, the content probably belongs in the page text where everyone can read it.

      You can check your own pages without special software. View the page source and search for <img: every match should have an alt attribute, empty or not. The developer tools in major browsers also include an accessibility panel that shows the name each image ends up with. Reading those names in a row, out of context, is a good test. If a list says "image, image, chart, logo", a screen reader user hears exactly that.

      Do not start alt text with "image of" or "picture of". Screen readers already announce that the element is an image, so the words are heard twice.
      Key points
      • Alt text gives the purpose of the image in its place on the page.
      • Decorative images get alt="", not a missing attribute.
      • Links and buttons made of an image need alt that names the action.
      • Long data belongs in text or a table next to the image.

      Practice questions from Alternative text for images on edubun

      Embed this quiz

      Free to embed. Please keep the credit line.

      Sources for this course (8)
      • W3C, Web Content Accessibility Guidelines (WCAG) 2.2, W3C Recommendation first published 5 October 2023, current edition 12 December 2024 (w3.org/TR/WCAG22/, checked 2026-10-17)
      • W3C WAI, What's new in WCAG 2.2 (w3.org/WAI/standards-guidelines/wcag/new-in-22/, checked 2026-10-17)
      • W3C WAI, Images tutorial and alt decision tree (w3.org/WAI/tutorials/images/decision-tree/, checked 2026-10-17)
      • W3C, Using ARIA (w3.org/TR/using-aria/, Discontinued Draft 24 February 2026, rules 1 to 4, checked 2026-10-17)
      • W3C WAI-ARIA Authoring Practices Guide, Read Me First, "No ARIA is better than bad ARIA" (w3.org/WAI/ARIA/apg/practices/read-me-first/, checked 2026-10-17)
      • MDN Web Docs, tabindex (developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/tabindex, checked 2026-10-17)
      • MDN, Heading elements, accessibility notes (developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/Heading_Elements, checked 2026-10-17)
      • MDN, autocomplete attribute (developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/autocomplete, checked 2026-10-17).

      Checked: 2026-10-17