Hreflang tags explained: when and how to use them
If you publish the same page in multiple languages or for multiple regions, you need hreflang tags. They tell search engines which version to show to which user. Without them, a French visitor might land on your English page, or worse, search engines might decide one of your language versions is duplicate content and drop it from the index.
What hreflang does (in plain terms)
The hreflang attribute is a hint to search engines that two or more pages are language or regional alternatives of each other. When a Spanish speaker in Mexico searches, hreflang helps search engines decide between your example.com/ (English), example.com/es/ (Spanish), and example.com/es-mx/ (Spanish, Mexico) versions and serve the one that fits.
It does NOT translate your page. It does NOT block other languages from being shown. It's just a hint about which version is the right match for a given language and country combination.
The format
<link rel="alternate" hreflang="LANG" href="URL" /> <link rel="alternate" hreflang="LANG-REGION" href="URL" />
Where:
- LANG is a two-letter ISO 639-1 code:
en,es,fr,de,ja,ar, etc. - REGION is an optional two-letter ISO 3166-1 alpha-2 code:
US,GB,MX,BR,DE, etc. Capitalized.
So hreflang="en-GB" means "English, United Kingdom." hreflang="fr" means "French, any region." hreflang="es-419" is the unusual one: UN M.49 region code for Latin America.
The x-default tag
There's one special value: hreflang="x-default". It marks the fallback page shown to users whose language and region don't match any of your other versions.
<link rel="alternate" hreflang="x-default" href="https://example.com/" />
Usually this points to your English version or to a language-picker page. x-default is recommended but not strictly required.
A full real-world example
Imagine you sell a product with three versions: English (default), Spanish for Spain, and Spanish for Mexico. On every one of those pages, you include the same set of tags:
<link rel="alternate" hreflang="en" href="https://example.com/product" /> <link rel="alternate" hreflang="es-ES" href="https://example.com/es/producto" /> <link rel="alternate" hreflang="es-MX" href="https://example.com/es-mx/producto" /> <link rel="alternate" hreflang="x-default" href="https://example.com/product" />
Critical: every page references every other page, including itself. This is called a "reciprocal" set. Without reciprocal references, search engines ignore the hreflang signal entirely.
The reciprocal rule
If page A says "page B is my Spanish alternative" but page B does not say "page A is my English alternative," search engines treat both as broken hreflang and ignore them. Always include the full set on every page in the group.
Where the tags can go
Three places. Only one method is used per page (they aren't mixed on the same page):
- In the HTML
<head>: most common for HTML pages. The link tags go before</head>. - In the sitemap.xml: useful for sites with many language versions. Each
<url>entry gets a set of<xhtml:link>children for its alternates. - In the HTTP response header: mainly for PDFs and other non-HTML files. Format:
Link: <url>; rel="alternate"; hreflang="es"
When you don't need hreflang
- Single-language site. Your blog in English only? Don't add hreflang.
- Different content per region. Hreflang is for the same content in different languages. If your US and UK pages are genuinely different (different products, different copy beyond translation), they're separate pages, not alternates.
- Different URLs for SEO testing. That's what canonical tags are for, not hreflang.
Common mistakes
- Using the wrong code. Common slips:
hreflang="uk"(means Ukrainian, not United Kingdom; useen-GB).hreflang="cn"is invalid; Chinese iszh.hreflang="jp"is invalid; Japanese isja. - Forgetting self-reference. The English page must include its own
hreflang="en"tag, not just the alternates. - Linking redirect URLs. Every URL in your hreflang set must be the final, 200-status URL. If you link to a URL that 301s elsewhere, search engines ignore it.
- Mixing canonical and hreflang in conflict. If your Spanish page has
rel="canonical"pointing to the English version, hreflang on either page gets ignored. The canonical wins. - Pointing to non-existent pages. 404s in your hreflang set break the whole cluster.
- Mixed protocols. If half your alternates are HTTPS and half HTTP, search engines may flag inconsistency. Use HTTPS for everything.
Generate your hreflang set in 60 seconds
Pick languages, paste URLs, get HTML or sitemap XML output. Validates ISO codes automatically.
How to verify hreflang is working
- Search-engine webmaster tools: under Indexing → International Targeting, the dashboard lists hreflang errors and warnings if any are found.
- View page source: open one of your alternate pages, find the
<link rel="alternate">tags, and click eachhref. They should all load with HTTP 200. - Crawl your site with a site-auditing tool. Most major SEO crawlers flag hreflang errors (missing reciprocals, broken links, invalid codes) across the entire site.