HTML href Attribute

The href attribute on an element defines a page or site to link to.

Its value can be an internal URL or an external URL.

Elements that accept this attribute include <a>, <area>, <link>, and <base>.



An <a> element with an href attribute.
Clicking the link opens a page from an external site in a new browser tab.

Go to Wikipedia
Go to <a href="" target="_blank">Wikipedia</a>

For additional details see our HTML anchor href Reference.

Using href

The href attribute specifies the URL or path of the linked page or resource.

It accepts any of these URLs:

  • absolute URL - link to a page on an external website or domain (e.g.
  • relative URL - link to an internal page on the same domain (with a shorter url)
  • anchor URL - link to an anchored section within the same page (with the # notation)


<tagname href="URL" >



Value Description
URL URL or path of the page or resource.

Elements that accept href

The following elements accept the href attribute.

Elements Description
<a> Specifies an anchor link -- see example above
<area> Creates a clickable area inside an image map.
<link> Adds a linked resource to the page.
<base> Sets all relative links base URL.

<area> with href

An <area> tag with an href attribute.

Computer Screen Keyboard Mouse
<img src="/img/html/computer-map.png" 

<map name="computermap">
  <area shape="rect" coords="253,142,16,2" alt="Screen" 
        href="javascript:alert('Screen was clicked');">
  <area shape="rect" coords="262,218,0,156" alt="Keyboard" 
        href="javascript:alert('Keyboard was clicked');">
  <area shape="circle" coords="267,234,22" alt="Mouse" 
        href="javascript:alert('Mouse was clicked');">

For additional details see our HTML area href Reference.

<link> with href

A <link> tag with an href attribute.
The invisible link loads a stylesheet into the page which is then used to style a paragraph.

Styled using external css.

<link rel="stylesheet" href="/tutorial/style.css">

<p class="aliceblue">Styled using external css.</p>

For additional details see our HTML link href Reference.

<base> with href

A <base> tag with an href attribute.

  <base href="">

  <a href="Vincent_van_Gogh">Vincent Van Gogh</a> <br />
  <a href="Henri_Matisse">Henri Matisse</a> <br />
  <a href="Paul_Cézanne">Paul Cézanne</a>

For additional details see our HTML base href Reference.

Browser support

Here is when href support started for each browser:

1.0 Sep 2008
1.0 Sep 2002
1.0 Aug 1995
1.0 Jan 2006
1.0 Jan 2003

You may also like

Last updated on Sep 30, 2023