HTML <a> href Attribute

The href attribute on an <a> (anchor) tag defines the page or site to link to. The href value can be an internal URL or an external URL.

Example

#

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

Go to Wikipedia
Go to <a href="https://en.wikipedia.org/wiki/Main_Page" target="_blank">Wikipedia</a>

Using href

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

It accepts any of these URLs:

  • absolute URL - link to a page on an external website or domain (e.g. https://wikipedia.com)
  • 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)

Note: If href is not set, the <a> element will not be treated as a link.


Syntax

<a href="URL" />

Values

#

Value Description
URL URL or path of the linked page.

Absolute URL

An <a> element with an absolute URL to Google.

<a href="https://www.google.com" target="_blank">Google</a>

Relative URL

An <a> element with a relative URL to our SQL Tutorial on this website.

<a href="/sql">SQL Tutorial</a>

Anchor URL

An <a> element with an anchor URL which scrolls to the top of this page.

Top
<a href="#top">Top</a>

Note: All browsers have a hidden <a id="top"> at the top which makes this work.
To jump elsewhere on the page you need to add <a id="mylocation"> to that location.


Browser support

Here is when href support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

 Back to <a>
Guides