Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

alt — text that replaces an image

`alt` conveys an image’s meaning or the purpose of an image link; empty text for decoration differs from a missing attribute.

Version: HTML Living Standard

Syntax

<img src="chart.svg" alt="Sales rose from 12 to 18 units">

For an informative img, describe the information needed in its context. If an image is a link’s only content, name the destination, such as “Browse courses”. A decorative image should use alt=""; omission does not declare decoration. alt is neither a title tooltip nor a keyword container.

It also applies to input type="image", where it names the button’s action, and to area with href, where it describes the image-map link. An area without href must omit alt. Empty area text is a specific exception for a second link to the same resource when a named link exists in that map.

The example compares a linked image with a decoration. The accessibility-tree test confirms the link name “Browse courses” and omission of the decorative image. Complex charts may additionally need a nearby description or data table.

Examples

<!doctype html><meta charset="utf-8">
<a href="#courses"><img id="linkImage" src="/mark.svg" alt="Browse courses"></a>
<img id="decoration" src="/mark.svg" alt="">
<output id="result"></output>
<script>
const image = document.querySelector('#linkImage');
const decoration = document.querySelector('#decoration');
document.querySelector('#result').textContent =
  'link=' + image.alt + '; decorative=' +
  (decoration.hasAttribute('alt') && decoration.alt === '');
</script>

Result

link=Browse courses; decorative=true

Besides the DOM, the test checks the link’s accessible name and exposed image count; it does not automatically judge every description’s quality.

Sources