What is hreflang and Why Does it Matter?
The **hreflang** attribute is a technical SEO specification introduced by Google in 2011 to solve the challenge of cross-border websites. If your website serves users in multiple countries or languages, you likely maintain duplicate or highly matching translated layouts. Without hreflang, search engines struggle to rank the appropriate local version, often leading to duplicate indexing warnings or mixed rankings.
Language vs. Region Codes
An hreflang tag can specify a language code alone, or combine it with a region code to target searchers in specific geographical locations:
- Language (ISO 639-1): A lowercase 2-letter code defining the language (e.g.
enfor English,esfor Spanish). - Region (ISO 3166-1 Alpha-2): An optional uppercase 2-letter code targeting a country (e.g.
GBfor United Kingdom,MXfor Mexico).
For example, en-US targets English speakers in the United States, whereas en-GB targets English speakers in the United Kingdom.
What is x-default?
The x-default tag is a special fallback value. It tells Google where to redirect users whose browser languages do not match any of the localized variants you have configured. A typical use case is a landing page presenting a country selector map, or a global English homepage.
HTML vs. XML Sitemap vs. HTTP Header Implementation
| Implementation Method | Pros | Cons | Best For |
|---|---|---|---|
| HTML Head Link Tags | Easy inline integration on small static sites. | Increases HTML page weight; harder to update across hundreds of subpages. | Small blogs, portfolios, corporate sites. |
| XML Sitemap Nodes | Leaves HTML page source clean; centralized database management. | XML files become large and complex; hard to build without custom CMS plugins. | E-commerce stores, large portals, dynamic sites. |
| HTTP Link Headers | Perfect for non-HTML files like PDFs, Word documents, or spreadsheets. | Requires server configuration access (Apache, Nginx, Cloudflare). | Document portals, download centers. |
Step-by-Step worked example
Suppose you run a product catalog. Your primary page is:https://mycatalog.com/item/ (English users)
And you have two translations:
1. French version: https://mycatalog.com/fr/item/
2. German version: https://mycatalog.com/de/item/
If you input these into our Hreflang tag builder:
- Specify the primary page URL and its language
en. - Add a variant for French: Language code
frand target URLhttps://mycatalog.com/fr/item/. - Add a variant for German: Language code
deand target URLhttps://mycatalog.com/de/item/. - Add an x-default pointing to your global site:
https://mycatalog.com/item/.
The resulting generated HTML output to copy is:<link rel="alternate" hreflang="en" href="https://mycatalog.com/item/" /><link rel="alternate" hreflang="fr" href="https://mycatalog.com/fr/item/" /><link rel="alternate" hreflang="de" href="https://mycatalog.com/de/item/" /><link rel="alternate" hreflang="x-default" href="https://mycatalog.com/item/" />
Implement this tag list in the head element of all three URLs.