Hreflang tags

Hreflang tags tell search engines which language/region version of your content to serve in which country. They're easy to understand, easy to implement, and stunningly easy to get wrong.

What they do

Suppose you have three versions of a page:

Hreflang tells Google: show the US version to users in the US, UK version to UK users, French version to French users. Without hreflang, Google guesses (often wrongly).

The syntax

Each page references every version (including itself). Three implementations, pick one:

1. HTML head tags (most common)

<link rel="alternate" hreflang="en-us" href="https://example.com/us/product" />
<link rel="alternate" hreflang="en-gb" href="https://example.com/uk/product" />
<link rel="alternate" hreflang="fr-fr" href="https://example.com/fr/product" />
<link rel="alternate" hreflang="x-default" href="https://example.com/us/product" />

2. HTTP headers (for non-HTML files)

Link: <https://example.com/us/product>; rel="alternate"; hreflang="en-us"

3. XML sitemap

<url>
  <loc>https://example.com/us/product</loc>
  <xhtml:link rel="alternate" hreflang="en-us" href="https://example.com/us/product"/>
  <xhtml:link rel="alternate" hreflang="en-gb" href="https://example.com/uk/product"/>
  ...
</url>

Valid language/region codes

x-default

The x-default tag specifies a fallback version for users whose language/region doesn't match any specific hreflang. Usually your US English or international-English version.

Common mistakes

The implementation nightmare

For a site with 10 languages × 20 countries = 200 page variations, every page needs 200 hreflang references. This gets unmaintainable fast in head tags. For large sites, XML sitemap hreflang is the sanity-preserving choice.

Testing

When NOT to use hreflang