HTML <img> altAttribute

HTML <img> Tag

Example

Image with specified alternative text:

<img src="smiley.gif.html" alt="Smiley face">

Try it Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the alt attribute.


Definition and Usage

The alt attribute is a required attribute that specifies alternative text when the image cannot be displayed.

Suppose for some reason (such as slow network speed, an error in the src attribute, the browser disabling images, or the user using a screen reader) the user cannot view the image, the alt attribute can provide alternative information for the image.

Note:When the user moves the mouse over the img element, Internet Explorer (versions before 9) displays the value of the alt attribute as a tooltip. According to the HTML specification, this behavior is not correct.

Tip:If you need to create a tooltip for an image, use thetitleattribute!


Differences between HTML 4.01 and HTML5

None.


Syntax

<img alt="text">

Attribute Values

Value Description
text Specifies the alternative text for the image.

Principles for using alt text:

  • If the image contains information, use alt to describe the image
  • If the image is inside an <a> element, use alt to describe the target link
  • If the image is for decoration only, use alt=""


HTML <img> Tag Other Extensions