References

Beginner-friendly references for web development, with live, editable examples.

The HTML hreflang attribute

Attribute All modern browsers Updated
Quick answer

The HTML hreflang attribute states the language of the linked resource using a BCP 47 code. It is used on the <a> and <link> elements.

Overview

The hreflang attribute states the language of the linked document. It is used on the <a> and <link> elements.

It relates to hyperlinks and linked resources — the destination, where it opens, the relationship to the current page, and security or privacy hints for the request.

Syntax

<a href="/fr/" hreflang="fr">Français</a>

Values

Value
A BCP 47 language tag, e.g. en, fr, pt-BR.

Best practices

  • Write descriptive link text — avoid "click here", which is meaningless out of context.
  • When using target="_blank", modern browsers add rel="noopener" for you, but set it explicitly for older ones.
  • Use rel values like nofollow, noreferrer and canonical deliberately for SEO and privacy.
  • Make sure links are distinguishable by more than color alone.

Frequently asked questions

What does the hreflang attribute do?
States the language of the linked document.
How do I open a link in a new tab?
Add target="_blank". Pair it with rel="noopener" for security in older browsers.
What does the rel attribute do on a link?
It states the relationship to the linked resource — for example nofollow, noreferrer, stylesheet or canonical.
Which elements use the hreflang attribute?
It is an element-specific attribute, used on the <a> and <link> elements.