Jump to content

Hreflang: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
 
(40 intermediate revisions by 32 users not shown)
Line 1: Line 1:
{{lowercase title}}
{{lowercase title}}
The <code>'''rel="alternate" hreflang="x"'''</code> 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.
The <code>'''rel="alternate" hreflang="x"'''</code> link attribute is a [[HTML]] [[meta element]] described in RFC 8288. '''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 ==
== 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.
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.<ref>{{Cite web |title=Versions localisées de vos pages {{!}} Google Search Central {{!}} Documentation |url=https://developers.google.com/search/docs/specialty/international/localized-versions?hl=fr |access-date=2023-12-11 |website=Google for Developers}}</ref>


Search engines use hreflang to understand the lingual and geographical targeting of websites and use the information to show the right [[URL]] in [[search engine technology|search results]], depending on user language and region preference.
Search engines use hreflang to understand the lingual and geographical targeting of websites and use the information to show the right [[URL]] in [[search engine technology|search results]], depending on user language and region preference.
Line 13: Line 13:
* Different countries, different languages
* Different countries, different languages
* Different countries, same language
* Different countries, same language
Hreflang attribute help your website deliver multiple variations of the website in different languages.<ref>{{Cite web |last=Shaikh |first=Gulammohiyuddin |date=29 November 2021 |title=A Guide To Hreflang Tag Best Practices For SEO |url=https://www.cswebsolutions.ca/blog/hreflang-tag-best-practices }}</ref>


== Implementation ==
== Implementation ==
Line 22: Line 23:


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.
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.
<ref>
{{Cite web |last=Kulagin |first=Kirill |date=13 December 2023 |title=List of Hreflang Country and Language Codes |url=https://keyrealseo.com/list-of-hreflang-country-and-language-codes/ |publisher=KeyRealSeo} }}</ref>


=== Language and Country Codes ===
=== 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.
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.
Line 33: Line 36:


'''Language and Region Example'''<br />
'''Language and Region Example'''<br />
<code>fr-CA</code><br>
<code>en-CA</code><br />
<code>en-CA</code><br />
<code>en-US</code><br />
<code>en-US</code>
<code>fr-CA</code>


The hreflang value has to follow the standard in order to be used by search engines.
The {{Mono|hreflang}} value has to follow the standard in order to be used by search engines.


=== Language Script Variations ===
=== Language script variations ===


RFC 5646 allows language script variations as value for hreflang. Language script variations can directly be addressed using [[ISO 15924]].
RFC 5646 allows language script variations as value for {{Mono|hreflang}}. Language script variations can directly be addressed using [[ISO 15924]].


'''Examples'''<br />
'''Examples'''<br />
Line 47: Line 50:
<code>zh-Hans: Chinese (Simplified)</code>
<code>zh-Hans: Chinese (Simplified)</code>


=== X-Default ===
=== 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.<ref>{{Cite web |url=https://support.google.com/webmasters/answer/189077?hl=en |title=Use hreflang for language and regional URLs |accessdate=2015-10-08 |publisher=Google Search Console Help}}</ref><ref>{{Cite web |url=http://googlewebmastercentral.blogspot.de/2013/04/x-default-hreflang-for-international-pages.html |title=Introducing "x-default hreflang" for international landing pages |accessdate=2015-10-08 |publisher=Google Webmaster Central Blog}}</ref>
{{Mono|x-default}} is a reserved {{Mono|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 defining an x-default version in each URL set, which will be shown to users from unspecified regions or languages in search results.<ref>{{Cite web |url=https://support.google.com/webmasters/answer/189077?hl=en |title=Use hreflang for language and regional URLs |accessdate=2015-10-08 |publisher=Google Inc.}}</ref><ref>{{Cite web |url=http://googlewebmastercentral.blogspot.de/2013/04/x-default-hreflang-for-international-pages.html |title=Introducing "x-default hreflang" for international landing pages |accessdate=2015-10-08 |publisher=Google Webmaster Central Blog}}</ref> Typically, in multilingual websites, the TLD (<nowiki>https://www.example.com</nowiki>) will get the x-default value in each URL set and the language folders/subdomains will be assigned hreflang values.


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.
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 ===
== Markup examples ==

Invalid hreflang usage can cause search engines to ignore the hreflang definitions for the entire website.

Common mistakes when using hreflang:<ref name="Audisto">{{Cite web |url=https://audisto.com/insights/guides/30/ |title=Hreflang attribute for multilingual and multi-region sites |accessdate=2015-10-08 |publisher=Audisto}}</ref>
* using underscore instead of hyphen in language and country value
* mixing up the order of the elements in language and country value
* using country without language
* using invalid language and country codes
* URL set not complete
* missing self-reference
* double usage of x-default with conflicting target URL
* multiple conflicting hreflang definitions
* defining a country code of EU
* defining a country code of UK rather than GB

== Markup Examples ==


=== HTML ===
=== HTML ===
<source lang="html4strict"><link rel="alternate" hreflang="en-US" href="http://example.com/page.html"></source>
<syntaxhighlight lang="html"><link rel="alternate" hreflang="en-US" href="http://example.com/page.html"></syntaxhighlight>


<source lang="html4strict">
<syntaxhighlight lang="html">
<html>
<html>
<head>
<head>
<link rel="alternate" hreflang="en-US" href="http://example.com/page.html">
<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-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="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="fr-CA" href="http://example.com/fr-ca/page.html">
<link rel="alternate" hreflang="x-default" href="http://example.com/page.html">
<link rel="alternate" hreflang="x-default" href="http://example.com/page.html">
</head>
</head>
<body>
<body>
...
...
</source>
</body>
</html>
</syntaxhighlight>


=== HTTP ===
=== HTTP ===
<source lang="http">
<syntaxhighlight lang="http">
HTTP/1.1 200 OK
HTTP/1.1 200 OK
Content-Type: application/pdf
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-UK",
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"
<http://us.example.com/page.pdf>; rel="alternate";hreflang="en-US"
...
...
</syntaxhighlight>
</source>


=== XML Sitemaps ===
=== XML sitemaps ===
<source lang="xml">
<syntaxhighlight lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
Line 157: Line 146:
</urlset>
</urlset>
...
...
</syntaxhighlight>
</source>


==References==
==References==

Latest revision as of 02:25, 11 April 2024

The rel="alternate" hreflang="x" link attribute is a HTML meta element described in RFC 8288. 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

[edit]

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.[1]

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

Hreflang attribute help your website deliver multiple variations of the website in different languages.[2]

Implementation

[edit]

Hreflang can be implemented in 3 different ways.

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. [3]

Language and country codes

[edit]

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
fr-CA
en-CA
en-US

The hreflang value has to follow the standard in order to be used by search engines.

Language script variations

[edit]

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

[edit]

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 defining an x-default version in each URL set, which will be shown to users from unspecified regions or languages in search results.[4][5] Typically, in multilingual websites, the TLD (https://www.example.com) will get the x-default value in each URL set and the language folders/subdomains will be assigned hreflang values.

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.

Markup examples

[edit]

HTML

[edit]
<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>
    ...
    </body>
</html>

HTTP

[edit]
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

[edit]
<?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

[edit]
  1. ^ "Versions localisées de vos pages | Google Search Central | Documentation". Google for Developers. Retrieved 2023-12-11.
  2. ^ Shaikh, Gulammohiyuddin (29 November 2021). "A Guide To Hreflang Tag Best Practices For SEO".
  3. ^ Kulagin, Kirill (13 December 2023). "List of Hreflang Country and Language Codes". KeyRealSeo}.
  4. ^ "Use hreflang for language and regional URLs". Google Inc. Retrieved 2015-10-08.
  5. ^ "Introducing "x-default hreflang" for international landing pages". Google Webmaster Central Blog. Retrieved 2015-10-08.