Preferences

Privacy is important to us, so you have the option of disabling certain types of storage that may not be necessary for the basic functioning of the website. Blocking categories may impact your experience on the website. More information (Cookie Policy)

Href Attribute: What It Is and How to Use It in HTML Links

The href attribute sets where an HTML link goes. Learn its values, the tags that use it, how Google reads it and the mistakes to fix.

Sorank customerSorank customerThomas Girauc, Sorank customerCelio Fabiano, Sorank customerSorank customerXavier Breull, Sorank customer
+ 9'000 Subscribers
Href Attribute: What It Is and How to Use It in HTML Links
Notification: your site reached 20K clicks from Google Search in 28 days

Tools

On this page

Summary

The href attribute is the HTML attribute that sets the destination of a link. Written inside an <a>, <area> or <link> tag, it holds a URL: another page, a section of the same page, a file, an email address or a phone number. Without href, an <a> tag is not a working link for browsers or search engines.

Want to go further? Ask

The href attribute (short for "hypertext reference") is the part of a link that tells the browser where to go. The visible words are the anchor text of the link; the href is the address behind them. For SEO, it matters for one simple reason: crawlers follow the href, not the text, the button style or the click handler. If the href is missing or wrong, the page behind it is harder to discover.

What does the href attribute do in HTML?

The href attribute gives a link its target URL. When you click, the browser loads the address written in href. When Googlebot reads the page, it extracts that same address and adds it to its list of pages to crawl.

The HTML standard states that hyperlinks are created by <a> and <area> elements with an href, and that without href "they do not create hyperlinks" (WHATWG HTML Living Standard, Links). The href value must be a valid URL. Here is the simplest form:

<a href="https://www.example.com/pricing">See our pricing</a>

Three parts make up this link: the opening <a> tag, the href attribute with its URL, and the anchor text between the tags. Change the href and the link goes somewhere else; the text stays the same.

Which HTML tags use the href attribute?

Four HTML tags accept href, and each uses it for a different job. Only two of them create clickable links.

TagWhat href doesExample
<a>Creates a clickable hyperlink in the page body<a href="/blog-geo-seo">Blog</a>
<area>Creates a clickable zone inside an image map<area shape="rect" coords="0,0,80,80" href="https://www.example.com/paris" alt="Paris">
<link>Points to a related resource in the head: stylesheet, canonical URL, alternate language version<link rel="canonical" href="https://www.example.com/shoes">
<base>Sets the base URL used to resolve every relative link on the page<base href="https://www.example.com/">

The <link> tag is where href meets technical SEO. Your canonical tag and your hreflang annotations for language versions both carry their target URL in an href. A typo there sends Google to the wrong page, with no visible sign on the page itself.

What values can you put in an href?

An href accepts any URL the browser understands, not only web pages. MDN lists tel:, mailto:, sms: and javascript: URLs, plus document fragments that point to a section of a page (MDN, the <a> element).

MDN reference page for the HTML a element, describing the href attribute and its supported URL types
Screenshot of developer.mozilla.org
<!-- Absolute URL: full address, protocol and domain -->
<a href="https://www.example.com/guide">Full guide</a>

<!-- Root-relative URL: starts from the domain root -->
<a href="/pricing">Our pricing</a>

<!-- Relative URL: starts from the current folder -->
<a href="../contact">Contact us</a>

<!-- Fragment: jumps to the element with id="faq" -->
<a href="#faq">Go to the FAQ</a>

<!-- Email, phone and SMS -->
<a href="mailto:[email protected]">Email us</a>
<a href="tel:+33123456789">Call us</a>
<a href="sms:+33123456789">Text us</a>

<!-- File download -->
<a href="https://www.example.com/files/price-list.pdf" download>Download the price list</a>

Fragment links are what people call jump links: they scroll to a heading with a matching id. Our article on creating jump links in HTML and your CMS covers them in detail.

Absolute or relative URL in href: which should you use?

Both work for users and for Google, so the choice is about maintenance. Google lists absolute URLs (https://example.com), root-relative paths (starting with /) and relative paths (starting with ./) as formats it can parse.

  • Absolute URLs (https://www.example.com/page): required for links to other sites, and the safest choice in canonical and hreflang tags, in emails and in RSS feeds, where there is no page to resolve from.
  • Root-relative URLs (/page): good for internal links. They survive a move from a staging domain to the live domain without edits.
  • Relative URLs (../page): short, but fragile. Move the page to another folder and every one of them may break.

Whatever you pick, the destination must be one clean, final URL with a consistent structure: same protocol, same www choice, same trailing slash rule. An internal href that points to a redirected address costs a hop on every crawl.

How does Google read the href attribute?

Google crawls a link only if it is an <a> element with an href that resolves to a real web address. Its documentation says it can "only crawl your link if it's an <a> HTML element" with an href attribute (Google Search Central, SEO link best practices).

Google Search Central page on SEO link best practices, showing crawlable and non-crawlable href examples
Screenshot of developers.google.com

Here are examples adapted from the same page, with what works and what to avoid:

<!-- Crawlable -->
<a href="/pricing">Pricing</a>
<a href="/pricing" onclick="javascript:goTo('pricing')">Pricing</a>

<!-- Not recommended -->
<a onclick="goto('https://example.com')">Shoes</a>
<span href="https://example.com">Shoes</span>
<a href="javascript:goTo('products')">Products</a>

The rule is easy to remember: keep your JavaScript if you need it, but always put the real URL in href. Google also notes that links inserted with JavaScript are crawlable, as long as they end up as proper <a href> elements in the rendered HTML. Our guide to JavaScript SEO and rendering explains how to check that. This is the base of crawlability: a page that no crawlable href points to may never be found.

Tip

Google also uses what surrounds the href. The anchor text should describe the target page, and for an image link, Google reads the image's alt attribute as anchor text.

The href sets where a link goes; rel and target change how it behaves. They sit on the same <a> tag.

  • rel="nofollow": tells Google you do not vouch for the target. Google asks you to use it only when you don't trust the source, not on every external link. See our definition of the nofollow link attribute.
  • rel="sponsored": for paid links, ads and affiliate links.
  • rel="ugc": for links added by users, such as forum posts and comments.
  • target="_blank": opens the link in a new tab. MDN notes that modern browsers apply rel="noopener" behaviour to it by default, and that you should tell users when a link opens a new tab.
<a href="https://partner.example.com" rel="sponsored" target="_blank">Partner offer (opens in a new tab)</a>

Common href attribute mistakes

Most href problems are invisible on screen: the link looks fine and still fails for crawlers or some users.

  1. Empty or missing href. What it is: <a>Shop</a> or <a href="">. How to spot it: a site audit flags "missing href", or a link that works only with a click handler. How to fix it: add the real destination URL.
  2. Fake links with href="#" or javascript:void(0). What it is: an anchor used as a button. MDN warns that these values break opening in a new tab, bookmarking and screen reader semantics. How to spot it: search your templates for href="#". How to fix it: use a <button> for actions and keep <a href> for navigation to a real URL.
  3. Broken destinations. What it is: an href pointing to a page that returns 404. How to spot it: run a crawl or a free broken link checker on your key pages. How to fix it: update the href or redirect the old URL. Our method to find and fix broken links at scale walks through each case.
  4. Internal links to redirects. What it is: an href pointing to an old URL that now redirects. How to spot it: a crawler shows internal links with a 301 status. How to fix it: replace the href with the final URL.
  5. Typos and wrong protocol. What it is: htps://, a missing slash, or http:// on an https site. How to spot it: extract every URL of the page and read the list. How to fix it: correct the value, ideally in the template so it stays fixed.

To see every href of a page in one list, split into internal and external links, paste the address into the Sorank URL extractor. It reads the HTML source, follows redirects and gives you lists you can copy into a spreadsheet.

Why does the href attribute matter for SEO and GEO?

The href is how search engines and AI crawlers move from one page to the next. Every internal linking structure you plan, every backlink you earn, only counts if the href is clean and crawlable.

  • Discovery: crawlers find new pages by following href values, alongside your XML sitemap.
  • Context: the href pairs a URL with anchor text, which helps search engines understand the target page.
  • Signals: rel values on the same tag tell Google which links you vouch for.
  • AI answers: assistants that search the web, like ChatGPT or Gemini, rely on crawlers to fetch pages. A link that only exists in a click handler gives a crawler no URL to follow.

In practice, a site with plain, correct <a href> links and descriptive anchors is easier to crawl, easier to understand and easier to cite.

Conclusion

The href attribute is a few characters, but it decides whether a link works for people, for Google and for the AI assistants that read your pages. Use <a href> with a real, final URL for every navigation link, keep buttons for actions, and check your pages regularly for empty, broken or redirected hrefs. For the bigger picture, read our definition of a link and how it shapes search visibility.

Sources

Frequently asked questions

What does href stand for in HTML?

Href stands for hypertext reference. It is the attribute that holds the URL a link points to, on tags like <a>, <area>, <link> and <base>.

Is a link without href crawlable by Google?

No, not reliably. Google says it can only crawl a link if it is an <a> element with an href attribute that resolves to a real web address. Links built only with onclick or javascript: values may not be followed.

Should I use href="#" for buttons?

No. MDN warns that href="#" and javascript:void(0) break behaviours like opening in a new tab and give wrong information to screen readers. Use a <button> for actions and keep <a href> for navigation to a real URL.

Our Blog for Ambitious Company

Testimonials from ambitious founders

0 to 10000 visitors in 5 months

Celio Fabianomonrobotlavevitre.frGoogleE-commerce

0 to 5000 visits in 8 months

Thibault BMsorank.comGoogleSoftware

0 to 1104 clicks in 4 months

Dominiqueflight-sensations-idf.comGoogleLeisure and aviation

0 to 163 clicks in 6 months

Coworking Pariscoworking-paris.frGoogleOffice broker

x92 clicks in 7 months

Guide Zanzibarguidezanzibar.comGoogleTravel