# Using `alt` attributes on `img` elements

ID: H37

Technology: html

Type: Technique

## When to Use

Images used within HTML documents.

## Description

When using the `img` element, specify a short text alternative with the `alt` attribute. Note. The value of this attribute is referred to as "alt text".

When an image contains words that are important to understanding the content, the alt text should include those words. This will allow the alt text to play the same function on the page as the image. Note that it does not necessarily describe the visual characteristics of the image itself but must convey the same meaning as the image.

## Examples

An image on a Website provides a link to a free newsletter. The image contains the text "Free newsletter. Get free recipes, news, and more. Learn more." The alt text matches the text in the image.

    <img src="newsletter.gif" alt="Free newsletter.
     Get free recipes, news, and more. Learn more.">

An image on a Web site depicts the floor plan of a building. The image is an image map with each room an interactive map area. The alt text is "The building's floor plan. Select a room for more information about the purpose or content of the room." The instruction to "select a room" indicates that the image is interactive.

## Tests

### Procedure

1. Examine each `img` element in the content.
2. Check that each `img` element which conveys meaning contains an `alt` attribute.
3. If the image contains words that are important to understanding the content, the words are included in the text alternative.

### Expected Results

Checks #2 and #3 are true.

## Related Techniques

- G82
- H2
- H24
- H30

## Resources

- HTML - `img` element.
- HTML - `alt` attribute.
- HTML - Requirements for providing text to act as an alternative for images.