Definition
- When a page has versions for other languages or regions,
hreflangtells Google about them so it can show each searcher the right one. It goes in<link rel="alternate">elements in the<head>, in aLinkresponse header, or in the sitemap. - Its value is an ISO 639-1 language code, optionally followed by an ISO 3166-1 Alpha 2 region code after a hyphen, such as
ar-SA. The valuex-defaultmarks the version for searchers no other version fits.
Why it matters
- On a site in Arabic and English,
hreflanglinks the Arabic page to its English version, so Google shows each searcher the version for their language. - Country versions in Arabic, such as
ar-SAandar-AE, are duplicates while their text is the same;hreflangtells Google they are local versions of the same content. Add a genericarversion for Arabic searchers elsewhere. - If two pages do not both point to each other, Google ignores the tags. And Google does not use
hreflangorlangto detect a page's language: its algorithms do.
Example
The Arabic page at the root and the English one under /en/, with the same tags in the <head> of both:
html
<link rel="alternate" hreflang="ar" href="https://example.com/" />
<link rel="alternate" hreflang="en" href="https://example.com/en/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/" />Each version lists itself and the others, with fully qualified URLs.
Common mistakes
- Missing return links: the Arabic page points to the English one, but the English page does not point back.
- Codes from outside the standards:
UKinstead ofGB,KSAandUAEinstead ofSAandAE, and an underscore, as inar_SA, instead of a hyphen. - A country code on its own:
SAalone is the language code for Sanskrit, not Saudi Arabia. - Relative URLs such as
/en/, orhttpURLs instead of the canonicalhttpsones.