hreflang
The rel="alternate" hreflang="x"
link attribute is a HTML meta element described in RFC 5988. Hreflang specifies the language and optional geographic restrictions for a document. Hreflang is interpreted by search engines and can be used by webmasters to clarify the lingual and geographical targeting of a website.
Purpose
Many websites are targeted at audience with different languages and localized for different countries. This can cause a lot of duplicate content or near duplicate content, as well as targeting issues with users from search engines.
Search engines use hreflang to understand the lingual and geographical targeting of websites and use the information to show the right URL in search results, depending on user language and region preference.
There are 3 basic scenarios that can be covered with hreflang:
- Same country, different languages
- Different countries, different languages
- Different countries, same language
Implementation
Hreflang can be implemented in 3 different ways.
- link element in HTML <head>
- HTTP header
- XML sitemaps
The hreflang definition is done by creating a full set of all language and region specific versions of the same document. Every URL in the set must reference the full URL set. A self-reference is required, so the including document has to be always part of the URL set.
Language and Country Codes
Hreflang accepts values that define languages ISO 639-1 and countries (ISO 3166-1). A language or a combination of language and region can be used as a value. A country-only value is not allowed.
Language Example
en
fr
be
Language and Region Example
en-CA
en-US
fr-CA
The hreflang value has to follow the standard in order to be used by search engines.
Language Script Variations
RFC 5646 allows language script variations as value for hreflang. Language script variations can directly be addressed using ISO 15924.
Examples
zh-Hant: Chinese (Traditional)
zh-Hans: Chinese (Simplified)
X-Default
x-default is a reserved hreflang value that can be used to specify a default version for a document. The x-default URL is not targeted at a specific region and/or language and is supposed to be shown to unspecified users. Google suggests to define an x-default version in each URL set, which will be shown to users from unspecified regions or languages in search results.[1][2]
The URL that is defined as the x-default for a certain document, can also be specified for a certain language or language and region at the same time.
Common Mistakes
Invalid hreflang usage can cause search engines to ignore the hreflang definitions for the entire website.
Common mistakes when using hreflang:[3]
- Using underscore instead of hyphen in language and country value
- Invalid order of the elements in language and country value
- Using only country without language
- Using invalid language and country codes
- No self-referencing hreflang tag
- More than one URL is specified for the same hreflang value
- Hreflang link points to redirected page
- Double usage of x-default with conflicting target URL
- Defining a country code of EU
- Defining a country code of UK rather than GB
- Conflicting hreflang and rel=canonical tags
- Broken hreflang link
- Using relative links
Markup Examples
HTML
<link rel="alternate" hreflang="en-US" href="http://example.com/page.html">
<html>
<head>
<link rel="alternate" hreflang="en-US" href="http://example.com/page.html">
<link rel="alternate" hreflang="en-CA" href="http://example.com/en-ca/page.html">
<link rel="alternate" hreflang="en-GB" href="http://example.com/en-gb/page.html">
<link rel="alternate" hreflang="fr-CA" href="http://example.com/fr-ca/page.html">
<link rel="alternate" hreflang="x-default" href="http://example.com/page.html">
</head>
<body>
...
HTTP
HTTP/1.1 200 OK
Content-Type: application/pdf
Link: <http://example.com/page.pdf>; rel="alternate";hreflang="x-default", <http://uk.example.com/page.pdf>; rel="alternate";hreflang="en-GB",
<http://us.example.com/page.pdf>; rel="alternate";hreflang="en-US"
...
XML Sitemaps
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>http://example.com/page.html</loc>
<xhtml:link
rel="alternate"
hreflang="en-US"
href="http://us.example.com/page.html"
/>
<xhtml:link
rel="alternate"
hreflang="en-GB"
href="http://uk.example.com/page.html"
/>
<xhtml:link
rel="alternate"
hreflang="x-default"
href="http://example.com/page.html"
/>
</url>
<url>
<loc>http://us.example.com/page.html</loc>
<xhtml:link
rel="alternate"
hreflang="en-GB"
href="http://uk.example.com/page.html"
/>
<xhtml:link
rel="alternate"
hreflang="x-default"
href="http://example.com/page.html"
/>
<xhtml:link
rel="alternate"
hreflang="en-US"
href="http://us.example.com/page.html"
/>
</url>
<url>
<loc>http://uk.example.com/page.html</loc>
<xhtml:link
rel="alternate"
hreflang="en-US"
href="http://us.example.com/page.html"
/>
<xhtml:link
rel="alternate"
hreflang="x-default"
href="http://example.com/page.html"
/>
<xhtml:link
rel="alternate"
hreflang="en-GB"
href="http://uk.example.com/page.html"
/>
</url>
</urlset>
...
References
- ^ "Use hreflang for language and regional URLs". Google Search Console Help. Retrieved 2015-10-08.
- ^ "Introducing "x-default hreflang" for international landing pages". Google Webmaster Central Blog. Retrieved 2015-10-08.
- ^ "13 Most Common Hreflang Mistakes - SEMrush Study". Retrieved 2018-06-28.