Hreflang Tags: How to Set Them Up and Validate
Hreflang tells Google that several URLs are the same content for different languages or regions, and which one to show to whom. It is not a ranking boost and it is not a redirect. It is a mapping, and like any mapping it is only useful when every entry agrees with every other entry.
Three ways to declare it
Pick one and use it consistently. In HTML, every page in the cluster lists every page in the cluster, including itself:
<link rel="alternate" hreflang="en" href="https://example.com/page" />
<link rel="alternate" hreflang="en-gb" href="https://example.com/uk/page" />
<link rel="alternate" hreflang="de" href="https://example.com/de/seite" />
<link rel="alternate" hreflang="x-default" href="https://example.com/page" />
For non-HTML files such as PDFs, use the HTTP Link response header. For large sites, the XML sitemap form keeps the markup out of the pages entirely and is easier to generate correctly:
<url>
<loc>https://example.com/page</loc>
<xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/seite"/>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/page"/>
</url>
Getting the codes right
A value is a language, optionally a script, optionally a region: ISO 639-1 for the language (two letters), ISO 15924 for the script (four letters), ISO 3166-1 alpha-2 for the region (two letters). Language alone is valid. Region alone is not.
| Value | Valid | Means |
|---|---|---|
en | yes | English, any region |
en-gb | yes | English as used in the United Kingdom |
zh-Hant-tw | yes | Traditional Chinese script, Taiwan |
x-default | yes | the fallback for locales you do not target |
en-uk | no | UK is not the ISO region code. Use en-gb |
en_us | no | the separator is a hyphen, not an underscore |
uk | misleading | valid, but it means Ukrainian, not the United Kingdom |
gb | no | a region with no language. Write en-gb |
One documented exception: Google accepts es-419 for Latin American Spanish, where 419 is a UN M49 region code rather than a two-letter ISO one. Strict validators flag it, and in that single case the validator is wrong.
The four rules that break most setups
- Self-reference: each page must list itself among the alternates. A cluster where pages only point outward is incomplete and often ignored.
- Reciprocity: if A points at B, B must point back at A. Google treats one-way declarations as unconfirmed, because otherwise any site could claim to be your alternate.
- Canonical agreement: a page that lists itself as an alternate must also canonicalize to itself. A page that says "my canonical is elsewhere" and "I am the German version" is contradicting itself, and hreflang loses.
- Indexable targets: alternates must return 200 and be indexable. Hreflang pointing at a redirect, a 404, or a
noindexpage does nothing.
Common errors and their fixes
| Symptom | Cause | Fix |
|---|---|---|
| Invalid language code reported | a region used as a language (gb, eu), or an invented one (en-uk) | use language, then optional region: en-gb |
| One code, two URLs | a templating bug, or two regional sites both claiming en | make the codes specific: en-us and en-gb, with en or x-default for the rest |
| Relative URLs in hreflang | copied from an internal link | hreflang requires absolute URLs, including the scheme |
| No return link | the alternate is generated from a partial list, or was added to one page only | generate the same complete cluster on every page from a single source |
| Canonical conflict | a parameter or tracking variant canonicalizing away while still declaring alternates | declare hreflang only on canonical URLs |
| Cluster ignored entirely | the alternates are blocked by robots.txt, so Google cannot verify the return links | let crawlers reach every URL in the cluster |
How to validate a cluster
- List the hreflang entries on the page and confirm every code is well formed.
- Confirm the page lists itself, with exactly the URL that is canonical for it.
- Confirm one entry is
x-defaultif you have visitors outside your targeted locales. - Fetch each alternate URL. Check the status is 200, that it is indexable, and that it declares the same cluster back.
- Confirm no code appears twice with different destinations.
- Spot-check in Search Console, which reports hreflang problems it found while crawling, including missing return links.
Steps one to three are readable from the page you are on. Steps four onward need a request to each alternate, which is why a page-level checker can confirm your syntax but only a crawl can prove reciprocity.
Common questions
Is hreflang a ranking factor?
No. It does not make a page rank higher. It changes which version of a page is shown to which searcher, which usually improves engagement and reduces the chance that your English page competes with your German one.
Do I need x-default?
It is recommended rather than required. Without it, a visitor whose locale matches none of your alternates gets whichever version Google considers the best guess. With it, you decide. If you have a language selector or a global English page, that is the natural x-default.
Is en-UK valid?
No. The ISO 3166-1 alpha-2 code for the United Kingdom is GB, so the correct value is en-gb. Values are case-insensitive, so en-GB and en-gb are equivalent, but UK is simply not a region code.
Do I still need hreflang if my pages are in different languages on different domains?
Yes, and it works across domains. Country-code domains give Google a strong geotargeting signal on their own, but hreflang is what maps the equivalent pages to each other so signals consolidate and the right version is shown.