The hreflang (alternate) tag is an HTML attribute used to indicate local versions of pages. If pages have multiple language versions, the hreflang tag should be used to indicate to search engines that these pages have different versions.
It’s especially important for multilingual and multi-regional websites, because it helps Google (and other search engines) serve the correct version of a page based on the user’s language or location.
en-ca
en-au
rel="alternate"
-> Will not change, it tells the search engine there is an alternate versionhref="page-url"
-> the URL of the alternate pagehreflang="xx-YY"
-> language and optional region codexx
= ISO 639-1 language code (e.g., en
, es
, fr
).YY
= ISO 3166-1 alpha-2 country code (e.g., US
, GB
, MX
).en-us
→ English (United States)en-gb
→ English (United Kingdom)es-mx
→ Spanish (Mexico)Region code is optional; for example, the following just uses language codes.
Each page must include its own hreflang reference as well as references to the other language versions.
x-default:
Used to indicate a fallback URL for unmatched language (e.g., a global homepage or language selector).
<link rel="alternate" href="https://juniortoexpert.com/de/namenskonvention-fur-variablen/" hreflang="de" />
<link rel="alternate" href="https://juniortoexpert.com/en/naming-convention/" hreflang="en" />
<link rel="alternate" href="https://juniortoexpert.com/es/convenio-de-denominacion-camel-case-kebab-case-snake-case/" hreflang="es" />
<link rel="alternate" href="https://juniortoexpert.com/fr/convention-de-denomination-des-variables/" hreflang="fr" />
<link rel="alternate" href="https://juniortoexpert.com/tr/degisken-isimlendirme-kurallari/" hreflang="tr" />
<link rel="alternate" href="https://juniortoexpert.com/ru/naming-convention-ru/" hreflang="ru" />
<link rel="alternate" href="https://juniortoexpert.com/en/naming-convention/" hreflang="x-default" />
Each alternate URL must be fully qualified, including the domain name, path, and transport method (http or https;)
https://juniortoexpert.com/en/naming-convention/
– True//juniortoexpert.com/en/naming-convention/
– False/en/naming-convention/
– FalseThe hreflang attribute must be placed inside the <head>
section of each page, and it is only used with the <link>
tag.
Note: Alternate pages must point to each other. If two pages don’t both point to each other, the tags will be ignored.
Yes, if you operate separate sites for different countries or languages, you can still use the hreflang tag to tell search engines which version belongs to which audience.
Allowed setups:
en.example.com
, fr.example.com
example.com/en/
, example.com/fr/
example.com
, example.fr
, example.de
Reciprocal linking required:
example.com
points to example.fr
with hreflang, then example.fr
must also point back to example.com
.Consistency matters:
https://
).On https://example.com/en/:
<link rel="alternate" href="https://example.com/en/" hreflang="en" />
<link rel="alternate" href="https://example.fr/fr/" hreflang="fr" />
<link rel="alternate" href="https://example.de/de/" hreflang="de" />
On https://example.fr/fr/:
<link rel="alternate" href="https://example.com/en/" hreflang="en" />
<link rel="alternate" href="https://example.fr/fr/" hreflang="fr" />
<link rel="alternate" href="https://example.de/de/" hreflang="de" />
On https://example.de/de/:
<link rel="alternate" href="https://example.com/en/" hreflang="en" />
<link rel="alternate" href="https://example.fr/fr/" hreflang="fr" />
<link rel="alternate" href="https://example.de/de/" hreflang="de" />
Do I need to use hreflang if my site is only in one language?
No. If your site has only one language and one regional version, hreflang is not necessary. It’s only useful when you have multiple languages or country versions of the same content.
Can I use hreflang with different domains?
Yes. Hreflang works with subdirectories, subdomains, or completely different domains. The key rule is that all versions must reference each other consistently.
What’s the difference between hreflang and canonical tags?
What happens if hreflang is wrong or missing?
Source:
https://developers.google.com/search/docs/specialty/international/localized-versions