HTML href Attribute: It is used to specify the URL of the document. It contains the full address of the page that the user requests. It is used to link or connect one document to another document.
Supported tags:
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">
Example: Below code illustrates the href attribute in <a> element.
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML href attribute</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML a href Attribute</h2>
<a href="https://ide.geeksforgeeks.org/">
Click to open in the same tab
</a>
<br />
<a href="https://ide.geeksforgeeks.org/" target="_blank">
Click to open in a different tab
</a>
</body>
</html>
Output:
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">
Example: Below code illustrates the href in <base> tag.
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML href Attribute</title>
<!-- Declaring the base URL -->
<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>
</html>
Output:

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">
Example: Below code illustrates the use of href attribute in <area> tag.
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML href Attribute</title>
</head>
<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>
</html>
Output:
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">
Example: Below code illustrates the use of href attribute in the <link> tag.
HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML href Attribute</title>
<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>
</html>
Output:

how to use the link attribute
Supported Browsers:
HTML href Attribute – FAQs
What types of URLs can be used with the href attribute?
The href attribute can use absolute URLs (full web address) or relative URLs (path relative to the current page) and can link to other resources like files (PDF, images).
How do you open a link in a new tab using the href attribute?
To open a link in a new tab, use the target attribute along with href, like this: <a href=”https://www.example.com” target=”_blank”>Visit Example</a>.
Can the href attribute link to sections within the same page?
Yes, the href attribute can link to a specific section within the same page using an ID selector. Example: <a href=”#section1″>Go to Section 1</a> and <div id=”section1″>Content</div>.
How do you use the href attribute to link to an email address?
To link to an email address, use mailto: followed by the email. Example: <a href=”mailto:someone@example.com”>Email Us</a>.
What happens if the href attribute is empty or missing?
If the href attribute is empty (href=””), clicking the link typically does nothing. If it is missing, the browser does not treat it as a clickable link.