Latest web development tutorials

HTML img alt attribute

HTML img tag Reference Manual HTML <img> tag

Examples

Specify an alternative text with image:

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

try it"

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the alt attribute.


Definition and Usage

alt attribute is a required attribute that specifies alternate text when the image can not be displayed.

Suppose for some reason (such as speed is too slow, src attribute errors, disable browser images, the user is using a screen reader) the user can not view the image, alt attribute provides alternative information for the image.

Note: When users move the mouse to the img element, Internet Explorer (9 previous versions) the value of the alt attribute is displayed as a tool tip.According to the HTML specification, this behavior is not correct.

Tip: If you need to create an image tooltip, use the title attribute!


Differences between HTML 4.01 and HTML5

no.


grammar

<img alt="text">

Property Value

描述
text 规定图像的替代文本。

alt 文本的使用原则:

  • 如果图像包含信息,使用 alt 描述图像
  • 如果图像在 <a> 元素中,使用 alt 描述目标链接
  • 如果图像仅供装饰,请使用 alt=""


HTML img tag Reference Manual HTML <img> tag