HTML href Attribute

Last Updated : 20 May, 2026

The HTML href attribute specifies the URL of a document, allowing one page to link and navigate to another.

HTML 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 , then the element will not be a hyperlink.

Syntax

HTML


<html>

<head>
    <title>HTML href attributetitle>
head>



<body>
    <h1>GeeksforGeeksh1>
    <h2>HTML a href Attributeh2>
    <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>



html>

HTML href Attribute

The HTML href attribute is used to specify the base URL for all the relative URL of a page.

Syntax

HTML


<html>

<head>
    <title>HTML href Attributetitle>
  
    


    <base href="geeksforgeeks.org" target="_blank" />
head>
<h2>GeeksforGeeksh2>
<h3>HTML base href Attributeh3>

<body>
    <img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210908192254/logo2.png" 
         width="200"
         height="200" />
body>



html>

HTML href Attribute

The href attribute is used to specify the URL of the target page. When the href attribute is not present in the , an element that it will not be a hyperlink.

Syntax

HTML


<html>

<head>
    <title>HTML href Attributetitle>
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 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>

The HTML href attribute is used to specify the URL of the linked document. It mostly contains the URL of the stylesheet file. 

Syntax

HTML


<html>

<head>
    <title>HTML href Attributetitle>


    <link id="linkid" rel="stylesheet" 
          type="text/css" 
          href="style.css" 
          sizes="16*16" 
          hreflang="en-us" />
head>

<body style="text-align: center">
    <h2>GeeksforGeeksh2>
    <b>link href Attributeb>
body>



html>