English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag大全

HTML: <img> alt attribute

If the user is unable to view the image for some reason (due to slow connection speed, incorrect src attribute, or the user uses a screen reader), the alt attribute provides alternative information for the image. If the image cannot be displayed, it is necessary to use the alt attribute to specify the alternative text for the image.

 HTML <img> tag

Online Example

Specified alternative text for the image:

<!DOCTYPE html>
<html>
<head>
<title>HTML: <img> alt attribute - Basic Tutorial Website oldtoolbag.com</title>
<body>
<img src="haha-no.gif" alt="haha face" width="42" height="42">
</body>
</html>
Test to see ‹/›

Browser compatibility

IEFirefoxOperaChromeSafari

All mainstream browsers support the alt attribute.

Definition and usage

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

If the image cannot be displayed, it is necessary to use the alt attribute to specify the alternative text for the image.

If the user cannot view the image for some reason (due to slow connection speed, incorrect src attribute, or the user is using a screen reader), the alt attribute provides alternative information for the image.

Note:When the user moves the mouse over the img element, Internet Explorer (9 (In previous versions) displaying the value of the alt attribute as a tooltip was incorrect according to the HTML specification.

Tip:If you need to create a tooltip for the image, please use title attribute!

HTML 4.01 with HTML5differences

None.

Syntax

<img alt="text">

attribute value

valuedescription
textSpecify the alternative text for the image.

Principles of using alt text:

  • If the image contains information, use alt to describe the image

  • If the image is within an <a> element, use alt to describe the target link

  • If the image is only for decoration, please use alt=""

 HTML <img> tag