Hreflang Generator: How It Works
Hreflang tells search engines that several URLs are the same content in different languages or for different regions, so each audience is shown the right version. It is conceptually simple and, in implementation, one of the most error-prone things in technical SEO.
The syntax
<link rel="alternate" hreflang="en-gb" href="https://example.com/uk/" /> <link rel="alternate" hreflang="en-us" href="https://example.com/us/" /> <link rel="alternate" hreflang="fr" href="https://example.com/fr/" /> <link rel="alternate" hreflang="x-default" href="https://example.com/" />
The value is a language code, optionally followed by a region code — fr for French anywhere, fr-ca for French in Canada. Language uses ISO 639-1, region uses ISO 3166-1 Alpha 2. Region alone is invalid: there is no hreflang="ca" meaning Canada, because ca is the language code for Catalan.
The three rules that break implementations
- Return links are mandatory. If page A lists B as an alternate, B must list A. One-way references are ignored entirely — this is the single most common failure.
- Every page must include itself. A complete set lists all versions including the current one.
- Hreflang must agree with canonical. Each version's canonical must point to itself. A page canonicalising to a different language version cancels the hreflang.
x-default
The x-default value marks the fallback for users whose language or region matches none of your versions — typically a global homepage or a language selector. It is optional but strongly recommended, because without it those users get whichever version the engine guesses.
Where to put the tags
| Method | Best for | Drawback |
|---|---|---|
HTML <head> | Small to medium sites | Every page carries every alternate — heavy at scale |
| HTTP header | PDFs and non-HTML files | Harder to inspect and debug |
| XML sitemap | Large sites, many languages | Changes are slower to be picked up |
Use exactly one method. Implementing the same set in two places invites contradictions when one is updated and the other is not.
What hreflang does and does not do
It is a signal for which version to show, not a ranking boost. It does not consolidate ranking signals — each version competes on its own merits — and it does not prevent versions from being treated as duplicates if the content is genuinely identical. Two English pages differing only in currency symbol may still be filtered as near-duplicates regardless of correct hreflang.
Errors worth checking for
- Underscores instead of hyphens:
en_gbis invalid. - Relative URLs — absolute URLs are required.
- Alternates pointing to redirecting or 404 URLs.
- Region codes used as language codes.
- Tags injected by JavaScript, which are unreliable for this purpose.
Search Console's International Targeting report surfaces missing return tags and unknown codes, and is the fastest way to find the mismatch in a large set.