Categories
HTML Web development

HTML href Attribute

HTML href Attribute

The HMTL href attribute defines the URL of the page the link goes to.

The HTML href attribute belongs to the following tags:

HTML <a> href Attribute

Syntax:

<a href="URL">

URL – the URL of the link.

Example:

<!DOCTYPE html>
<html>
<body>

<p>Click on the link: <a href="https://www.lenastanley.com/">CodeLife: Animations</a></p>

</body>
</html>

Output:

Click on the link: CodeLife: Animations

HTML <area> href Attribute

Syntax:

<area href="URL"> 

URL – defines the hyperlink target for the area.

Example:

<!DOCTYPE html>
<html>
<body>

<p>Click on the laptop, or the cup of coffee:</p>

<img src="https://lenadesign.org/wp-content/uploads/2021/06/homeOffice.jpg" alt="homeOffice" usemap="#workmap" width="640" height="480">

<map name="workmap">
  <area shape="rect" coords="34,44,270,350" alt="laptop" href="https://lenadesign.org/wp-content/uploads/2021/06/laptop.jpg">
  <area shape="circle" coords="337,300,44" alt="coffee" href="https://lenadesign.org/wp-content/uploads/2021/06/photoshop-gif.gif">
</map>

</body>
</html>

Output:

Click on the laptop or the cup of coffee:

<div class="ar">
<img src="https://lenadesign.org/wp-content/uploads/2021/06/homeOffice.jpg" alt="homeOffice" usemap="#workmap" width="640" height="480">

<map name="workmap">
  <area shape="circle" coords="280,210,45" alt="laptop" href="https://lenadesign.org/wp-content/uploads/2021/06/laptop.jpg">
  <area shape="circle" coords="160,210,45" alt="coffee" href="https://lenadesign.org/wp-content/uploads/2021/06/photoshop-gif.gif">
</map>
</div>

HTML <link> href Attribute

Syntax:

<link href="URL"> 

URL – the URL of the linked resource/document.

Example:

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="example-style.css">
</head>
<body>

<h4>This is a heading.</h4>

<p>This is a paragraph.</p>

<p>This is the second paragraph.</p>

</body>
</html>

Output:

Example CSS stylesheet

Read also:

HTML accesskey Attribute

HTML draggable Attribute

HTML style Attribute