What is hreflang
hreflang is used for multilingual and multi‑regional websites. It addresses duplicate content issues (same information in different languages) and helps Google choose the correct version for the user based on language and location.
Syntax and codes
html
<link rel="alternate" hreflang="ru" href="https://example.com/ru/" />
<link rel="alternate" hreflang="en" href="https://example.com/en/" />
<link rel="alternate" hreflang="en-US" href="https://example.com/en-us/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/" />Codes: language – ISO 639-1 (ru, en, de). Language+region – ISO 639-1 + ISO 3166-1 (en-US, en-GB, pt-BR). x-default points to the fallback version when no language/region matches.
Implementation methods
- HTML link in
<head>‑ the most common method for regular pages. - HTTP headers – for non‑HTML files (PDF, images, etc.).
- Sitemap – convenient for large sites where adding annotations to each page manually is heavy.
Example in sitemap.xml:
xml
<url>
<loc>https://example.com/ru/</loc>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/" />
<xhtml:link rel="alternate" hreflang="ru" href="https://example.com/ru/" />
<xhtml:link rel="alternate" hreflang="x-default" href="https://example.com/" />
</url>Common errors when using hreflang
- Missing self‑referencing (the page must point to itself)
- No
x-default - Incorrect language codes (e.g.,
rusinstead ofru) - Relative URLs (absolute URLs with https:// required)
- Asymmetric links (page A links to B, but B does not link back to A)
Test your hreflang using the 'International targeting' report in Google Search Console or third‑party testers (e.g., Aleyda Solis’s tool). Errors in hreflang may cause Google to ignore your annotations.
FAQ
Is x-default mandatory?
Yes, Google highly recommends adding
x-default to specify the version for users whose language or region is not covered by other annotations.Can I use hreflang together with canonical?
Yes. Each language version must have its own canonical pointing to itself. Do not set canonical to a different language version.
What if I have the same language but different regions (en-US, en-GB)?
Use separate hreflang tags with regions. Google will show en-US to US users and en-GB to UK users if those pages are optimized for the respective regions.