w3resource

HTML href attribute

href

The purpose of the HTML href attribute is to specify the URL for any kind of link or image map.

Supported elements

HTML href attribute supports a, area, base, link elements.

Syntax

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

Where ElementName is any supported elements.

Type of value

URL.

Value

A URL.

Default value

There is no default value of HTML href attribute.

Supported doctypes

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

Example of HTML href attribute with area

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML href attribute with area</title>
</head>
<body>
<img src="attributes-href-area.gif" alt="href area    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/tutorials.php" alt="sql tutorials">
</map>
</body>
</html>

Result

html href attribute with area
mysql tutorial php tutorial sql tutorials

Example of HTML href attribute with

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML href attribute with a</title>
</head>
<body>
<a href="https://www.w3resource.com">W3resource tutorials</a>
</body>
</html>

Result

html href attribute with a

View this example in a separate browser window

Example of HTML href attribute with a

Example of HTML href attribute with link

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML href attribute with link </title>
<link rel="icon" type="image/png" href="../../images/w3ricon.png" /> 
</head>
<body>
<p>We are learning HTML</p> 
</body>
</html>

Result

html href attribute with link

View this example in a separate browser window

Example of HTML href attribute with link

Example of HTML href attribute with base

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML href attribute with base</title>
<base href="https://www.w3resource.com/images/" /> 
<base target="_blank" />
</head>
<body>
<p><img src="w3logo5.gif" /></p><!--Only relative path to the image is provided. But since href="https://www.w3resource.com/images/" so actual image file will be fetched. And <base target="_blank" /> will open the image in a new tab.--> 
</body>
</html>

Result

html href attribute with base

View this example in a separate browser window

Example of HTML href attribute with base

Previous: HTML height attribute
Next: HTML hreflang 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-href-attribute.php