Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML href Attribute

  • Last Updated : 08 Sep, 2021

Example: In this example we simply redirect to the geeksforgeeks page by clicking on a text.

HTML

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




<!DOCTYPE html>
<html>
  <head>
    <title>HTML href attribute</title>
  </head>
  <body>
    <h1>
      <a href="https://www.geeksforgeeks.org/">
       GeeksforGeeks
      </a>
    </h1>
    <strong>HTML href Attribute</strong>
  </body>
</html>


Output:

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :