SEO
hreflang: how to connect language versions of a site
The essentials
- hreflang tells Google which version of a page to show based on the searcher’s language or country.
- It must be reciprocal: if the Spanish version points to the English one, the English one must point back.
- Each version includes itself in the list.
- Codes follow the standard: two-letter language and, if needed, country (
es-MX,en-GB).en-UKdoes not exist.
How to write it
The most common way is one tag per version in the <head> of every page, each with the full list:
<link rel="alternate" hreflang="es-MX" href="https://yoursite.com/" /> <link rel="alternate" hreflang="en" href="https://yoursite.com/en/" /> <link rel="alternate" hreflang="x-default" href="https://yoursite.com/" />
It can also go in the Link HTTP header (useful for PDFs) or in the sitemap. Pick one method: mixing them makes contradictions easy.
Why it must be reciprocal
Google only trusts a pair when both pages point to each other. If the English version does not point to the Spanish one, Google drops that relationship: it stops any site from declaring itself an “alternate version” of yours.
The SEO Army robots.txt, sitemap and hreflang tester reads each alternate and checks that it links back.
x-default
x-default is the version for people who fit none of the others: a language picker or the main version. It is optional, but it helps on sites with many countries.
Common mistakes
- The return link is missing: the English version does not link to the Spanish one.
- Made-up codes such as
en-UK(it isen-GB) ores-LA(it does not exist; usees-419or the country). - Alternates that redirect or return 404. Each address must return 200 and be its own canonical. More in Canonical URL: how to tell Google which version to index.
- Pointing every version to the same canonical. Each language is its own main page.
Check it