Open In App
Related Articles

HTML href Attribute

Improve Article
Improve
Save Article
Save
Like Article
Like

HTML href Attribute: It is used to specify the URL of the document. It contains the full address of the page that the user request. 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>
        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=
         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=
         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=
              alt="Triangle" />
        <area shape="circle" coords="155, 56, 26"
              href=
              alt="Circle" />
        <area shape="rect" coords="224, 30, 276, 82"
              href=
              alt="Square" />
    </map>
</body>
 
</html>


Output:

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">

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:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 05 Jun, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials