What Is The Hreflang Attribute?

What Is The Hreflang Attribute
Source: Seobility

Date First Published: 5th January 2023

Topic: Web Design & Development

Subtopic: SEO

Article Type: Computer Terms & Definitions

Difficulty: Medium

Difficulty Level: 6/10

Learn more about what the hreflang attribute is in this article.

The hreflang attribute is used to define the country and language a page is designed to serve so that search engines can serve that result for users searching in that language, show people the right website for their country in the search results, and solve duplicate content issues.

For example, even if the French version and the UK version of a website show the same content, search engines will know that they are written for different countries. Adding the hreflang attribute will signal to search engines that a user querying in language "a" will want this result instead of a page with similar content in language "b". This attribute was introduced by Google in December 2011 to better understand the international architecture of websites.

Using the hreflang attribute has a number of benefits. It will result in each user receiving only relevant search results, improving their user experience. Optimising pages for user's locations and languages is important for improving user experience.

Hreflang attributes are signals, not directives. Even though a correct hreflang attribute will affect Google's decision on which version of a webpage is most relevant to users, adding the tag does not guarantee that search engines will show the version that you want them to show to searchers. Search engines may not use them if they consider them to be inaccurate. Hreflang is supported by Google and Yandex, but Bing does not support it. Instead, Bing uses language meta tags.

Google recommends the use of the hreflang attribute in the following situations:

  • If there are multiple versions of a page that have been completely translated into different languages.
  • If multiple pages share the same language, but there are small regional differences such as different spellings. An example of this is two versions of a page for users in the US and users in the UK. In that case, it is important to use hreflang as Google might consider the two pages as duplicate content.
  • If multiple pages are only accessible from certain languages or countries.

Structure Of The Hreflang Attribute

The structure of the hreflang attribute is:

  • <link - Used to specify a relationship between the current document and an external resource.
  • rel="alternate" - Tells search engines that there is a different version of the current document.
  • hreflang="xx-XX": - Specifies which language and region the URL is designed to serve. Languages must be indicated in ISO 639-1 format and countries in the ISO 3166-1 Alpha 2 format.
  • href="URL" - Specifies the URL of the different version of the current document.
  • <> - The ending tag used to close the link element.

For example, if you have an English webpage and want to specify the Spanish version of it, you would insert the following line of code to the head of the HTML document.

<link rel="alternate" hreflang="es" href ="http://www.example.com/es/" />

The hreflang attribute can also be inserted into an XML sitemap, as shown below:

<url> <loc>https://www.example.com/uk/</loc> <xhtml:link rel="alternate" hreflang="es" href="https://www.example.com/es/" /> </url>

The benefits of adding the attribute to an XML sitemap are that it won't increase the file size of the HTML file with the extra markup and it is much easier to change an XML sitemap than to change all the pages on a site. However, a lot of output is required for large numbers of URLs.

Hreflang can also be used to show that there is content targeted toward variants of a single language. In that case, pages can be targeted more specifically by extending the hreflang attribute with annotations that indicate the region the content is designed for. For example, for Spain, the tag would be hreflang="es-es", and for Mexico, it will hreflang="es-mx".

Is The Hreflang Attribute A Ranking Factor?

No, the use of the hreflang attribute is not a direct ranking factor. Adding it will not cause it to rank higher in SERPs as that is too easy to manipulate. However, if hreflang links are missing or incorrectly implemented, search engines might consider the content of two different language versions as duplicate content, which will have a negative impact on the SEO.


Feedback

  • Is there anything that you disagree with on this page?
  • Are there any spelling, grammatical, or punctuation errors on this page?
  • Are there any broken links or design errors on this page?

If so, it is important that you tell me as soon as possible on this page.