The HTML href attribute specifies the URL of a document, allowing one page to link and navigate to another.
- Defines the destination address of a hyperlink.
- Commonly used with the <a> (anchor) tag.
- Can link to web pages, files, email addresses, or sections within a page.
- Enables navigation between different documents.
HTML <a> href Attribute
It is used to specify the URL of the page that the link goes to. When the href attribute is not present in the <a>, then the element will not be a hyperlink.
Syntax
<a href="URL"><!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>HTML href attribute</title>
</head>
<!--Driver Code Ends-->
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML a href Attribute</h2>
<a href="https://www.geeksforgeeks.org/community/">
Click to open in the same tab
</a>
<br />
<a href="https://www.geeksforgeeks.org/community/" target="_blank">
Click to open in a different tab
</a>
</body>
<!--Driver Code Starts-->
</html>
<!--Driver Code Ends-->
HTML <base> href Attribute
The HTML <base> href attribute is used to specify the base URL for all the relative URL of a page.
Syntax
<base href="URL"><!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>HTML href Attribute</title>
<!-- Declaring the base URL -->
<!--Driver Code Ends-->
<base href="geeksforgeeks.org" target="_blank" />
</head>
<h2>GeeksforGeeks</h2>
<h3>HTML base href Attribute</h3>
<body>
<img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210908192254/logo2.png"
width="200"
height="200" />
</body>
<!--Driver Code Starts-->
</html>
<!--Driver Code Ends-->
HTML <area> href Attribute
The <area> href attribute is used to specify the URL of the target page. When the href attribute is not present in the <area>, an element that it will not be a hyperlink.
Syntax
<area href="URL"><!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>HTML href Attribute</title>
</head>
<!--Driver Code Ends-->
<body style="text-align: center">
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190227165729/area11.png"
alt="alt_attribute"
width="300" height="119"
class="aligncenter" usemap="#shapemap" />
<map name="shapemap">
<!-- area tag contained image. -->
<area shape="poly" coords="59, 31, 28, 83, 91, 83"
href=
"https://media.geeksforgeeks.org/wp-content/uploads/20190227165802/area2.png"
alt="Triangle" />
<area shape="circle" coords="155, 56, 26"
href=
"https://media.geeksforgeeks.org/wp-content/uploads/20190227165934/area3.png"
alt="Circle" />
<area shape="rect" coords="224, 30, 276, 82"
href=
"https://media.geeksforgeeks.org/wp-content/uploads/20190227170021/area4.png"
alt="Square" />
</map>
</body>
<!--Driver Code Starts-->
</html>
<!--Driver Code Ends-->
HTML <link> href Attribute
The HTML <link> href attribute is used to specify the URL of the linked document. It mostly contains the URL of the stylesheet file.
Syntax
<link href = "url"><!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>HTML href Attribute</title>
<!--Driver Code Ends-->
<link id="linkid" rel="stylesheet"
type="text/css"
href="style.css"
sizes="16*16"
hreflang="en-us" />
</head>
<body style="text-align: center">
<h2>GeeksforGeeks</h2>
<b>link href Attribute</b>
</body>
<!--Driver Code Starts-->
</html>
<!--Driver Code Ends-->