What Is Hreflang?
Hreflang is a small piece of code that tells search engines what language and country a page is made for. It helps Google and other search engines show the right version of your page to the right people.
Definition
The hreflang attribute is an HTML tag or sitemap tag that connects similar pages in different languages or for different countries. It uses language and country codes, like en for English or en-gb for English in the United Kingdom.
Why Hreflang Matters
- Shows the right language Search engines can send Spanish users to your Spanish page, French users to your French page, and so on.
- Improves user experience Visitors see text they can read and understand right away.
- Helps SEO It reduces duplicate content problems when you have many similar pages in different languages.
- Targets countries You can tell search engines which page is for which market, like the United States, Canada, or Germany.
How Hreflang Works
Hreflang uses language and country codes in a special format.
- Language code a two letter code like
enfor English,esfor Spanish,frfor French. - Country code optional two letter code like
USfor United States,GBfor United Kingdom,CAfor Canada.
Together they look like en-us or es-mx. Search engines read these codes and decide which page to show based on the users language and location.
You can add hreflang in three main ways
- In the HTML head as
<link rel="alternate" hreflang="..." href="..."> - In XML sitemaps by listing each language version and its hreflang value
- In HTTP headers for non HTML files like PDFs
Hreflang vs Related Tags
- Hreflang vs canonical Canonical tells search engines which version is the main one when pages are very similar. Hreflang tells which version fits which language or country. You often use both together.
- Hreflang vs language meta tag The old
<meta http-equiv="content-language">tag is weak for SEO. Hreflang is the modern and stronger way to show language targeting.
Example of Hreflang
Imagine you have two pages
- English page for the United States
https://example.com/en-us/ - Spanish page for Mexico
https://example.com/es-mx/
In the HTML head of the English page, you might add
<link rel="alternate" hreflang="en-us" href="https://example.com/en-us/" />
<link rel="alternate" hreflang="es-mx" href="https://example.com/es-mx/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/" />
The Spanish page would list the same tags pointing back to the English page. This two way linking helps search engines understand the full set of language versions.
FAQs
Do I need hreflang if my site is only in one language
Probably not. Hreflang is most useful if you have more than one language or target several countries.
What is x default in hreflangx-default is a special value that tells search engines which page to use when no specific language or country match is found. It is often the global or language picker page.
Can hreflang fix automatic translation
No. Hreflang only helps choose the right page. You still need good human written translations for best results.
What happens if hreflang is wrong
If you use wrong codes or missing links, search engines might show the wrong language version or ignore the hreflang tags completely.
Does hreflang guarantee rankings
No. Hreflang helps with targeting and user experience but you still need strong content, fast pages, and good overall SEO to rank well.