Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML img alt attribute

HTML alt property

HTML img Tag Reference HTML tag

Example

An image with specified alternative text:

Smiley face

Try it »


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the alt property.


Definition and Usage

The alt property is a required property that specifies alternate text to display when the image cannot be shown.

The alt attribute can provide alternative information for an image, assuming the user cannot view it for some reason (such as a slow connection, an error in the src attribute, images disabled in the browser, or the user using a screen reader).

**Note:** When a user moves the mouse over an 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 the title attribute!


Differences between HTML 4.01 and HTML5

none.


Syntax

</p>
<p>text</p>
<p>

Attribute values

Value Description
text Specifies alternative text for an image.

Guidelines for using alt text:

  • If the image contains information, use alt to describe the image
  • If the image is in the element, use alt to describe the target link
  • If the image is purely decorative, use alt=""
  • |

    HTML img Tag Reference HTML tag