w3resource

HTML alt attribute

alt

The purpose of the HTML alt attribute is to specify a short description for the supported elements.

Supported elements

HTML alt attribute supports area, img, input elements.

Syntax

<ElementName alt="value" >.....</ElementName>

Where ElementName is any supported element.

Type of value

Type of value of HTML alt attribute is text.

Value

A piece of text containing a short description of the adjacent content.

Default value

There is no default value of HTML alt attribute.

Supported doctypes

HTML 4.01 strict, HTML 4.01 transitional, HTML 4.01 frameset.

Example of HTML alt attribute with img and area

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML alt attribute with area and img </title>
</head>
<body>
<img src="attribute-alt-img-area.gif" alt="alt example  " width="308" height="190" border="0" usemap="#Map">
<map name="Map">
<area shape="rect" coords="8,5,100,77"   href="../../mysql/mysql-tutorials.php" target="_blank" alt="mysql   tutorial">
<area shape="circle" coords="155,93,59" href="../../php/php-home.php" target="_blank" alt="php tutorial">
<area shape="rect" coords="197,136,306,188" href="../../sql/sql-tutorials.php" alt="sql tutorials">
</map>
</body>
</html>

Result

html alt attribute with img and area

View this example in a separate browser window

Example of HTML alt attribute with img and area.

Example of HTML alt attribute with input

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example of HTML alt attribute with input</title>
</head>
<body>
<form action="action.php">
Email id : <input type="text" name="email" alt="Your Email id"/><br />
Password : <input type="text" name="passw" alt="Your Password"/><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>

Result

html alt attribute with input

View this example in a separate browser window

Example of HTML alt attribute with input.

Previous: HTML align attribute
Next: HTML archive attribute

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/html/attributes/html-alt-attribute.php