Image altAttribute

Image 对象参考手册Image Object

Definition and Usage

The alt attribute can set or return the alt attribute value of an image.

The alt attribute specifies the alternate text to be displayed when the image cannot be displayed normally (slow network speed, broken image link).

Note:Internet Explorer displays a tooltip when the mouse moves over an img element, which is non-standard according to the HTML specification. All other browsers only display the alt text when the image cannot be displayed.

Tip:If you want to create an image tooltip, use the title attribute.

Syntax

imageObject.alt=text


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the alt attribute


Example

Example

Return the alternate text of the image:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
</head>
<body>

<img id="compman" src="compman.gif.html" alt="Crazy computerman" width="107" height="98">
<p>The alt attribute value is:
<script>
document.write(document.getElementById("compman").alt);
</script>
</p>

</body>
</html>

Try it yourself »


Image 对象参考手册Image Object Other Extensions