The HTML hreflang attribute
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
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 addrel="noopener"for you, but set it explicitly for older ones. - Use rel values like
nofollow,noreferrerandcanonicaldeliberately 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.