Alt attribute

The alt attribute is used in HTML and XHTML documents to specify alternative text (alt text) that is to be rendered when the element to which it is applied cannot be rendered. In HTML 4.01, the attribute is required for the  and   tags. It is optional for the  tag and the deprecated   tag.

The syntax of the alt attribute is:





or



Example
Here is an image whose alt attribute is "In the sky flies a red flag with a white cross whose vertical bar is shifted toward the flagpole."



The HTML for this image might be something like the following:

 

A visually impaired reader, who is using a screen reader such as JAWS or Orca, will hear the alt text in place of the image. A text browser such as Lynx will display the alt text instead of the image. A graphical browser typically will display only the image, and will display the alt text only if the user asks it to show the image's properties. Many graphical browsers can be configured to show the alt text instead of the image.

An alternative alt attribute value would be "The Danish flag".

Common misconceptions
attribute is not supposed to literally describe contents of the image. It's supposed to be an alternative for the image, usually stating its purpose. For example image of a warning sign should not have alt text "a triangle with yellow background, black border and exclamation mark", but simply "Warning!".

Internet Explorer 7 and earlier render text in alt attributes as tooltip text in standards non-compliant manner. This behavior led many web developers to misuse alt when they wished to display tooltips containing additional information about images, instead of using the  attribute that was intended for that use. As of Internet Explorer 8 alt attributes no longer render as tooltips.

The alt attribute is commonly, but incorrectly, referred to as the "alt tag".