Images can carry details that the surrounding words leave out. In HTML, the alt attribute gives an informative image a text alternative that a screen reader can announce.

The same picture can serve different purposes on different pages. A footbridge illustration might show where a trail crosses a creek, while a flourish beside it simply decorates the page. A decorative image stays visible with empty alt text, but omitting the attribute can leave a screen reader announcing its filename.

An image can also be the only content of a link or button. In that case, its alt text should tell the reader where the link goes or what the button does.

Steps to add accessible image alt text in HTML:

  1. Open the local HTML file containing the images in your text editor.

    The park page already contains two <img> tags in park.html. The footbridge image conveys information about the trail, and the flourish is purely decorative.

  2. Add a descriptive alt attribute inside the informative image's <img> tag.
    alt="Creek footbridge"

    The attribute goes before the closing >. Your image keeps its existing src and other attributes. If the tag already has an alt attribute, replace its value. The words should convey the detail the reader would miss without the image.

  3. Set the decorative image's alt value to an empty string.
    alt=""

    The quotes contain no spaces. W3C's decorative image examples show how to decide when empty alt text fits.

  4. Save the HTML file.
  5. Open the saved HTML file in desktop Chrome.

    The example opens park.html from a local folder. If your page is already open, reloading it picks up the saved edit.

  6. Right-click the informative image on the page.
  7. Select Inspect in the image context menu.
  8. Open More Tabs at the end of the Elements sidebar tab row if Accessibility is hidden.
  9. Select Accessibility in the Elements sidebar.
  10. Verify that alt supplies the informative image's intended accessible name under Computed properties.

    On the park page, Name reads Creek footbridge, with alt shown as the active source beneath it. If the sources are hidden, expand Name with its disclosure arrow. The check fails if the name is empty, differs from the intended description, or comes from another source.

  11. Select the decorative image's <img> tag in the Elements tree.

    In the example, flourish.png is directly below footbridge.png.

  12. Verify that Computed properties reports Element has empty alt text for the decorative image.

    Chrome shows this message when it skips exposing the image. If the pane still gives the decoration an image role, that image is still exposed to assistive technology.

Share this guide