Start Exploring Keyword Ideas

Use Serpstat to find the best keywords for your website

15404
How-to 14 min read January 19, 2022

How To Add Lang And Hreflang Attributes To The Page Code

Lang and hreflang HTML attributes are necessary for indication page references, created from a variety of languages. They help to search systems to have the output results, optimized for a special area, language, or dialect.

What are lang and hreflang attributes?

If the company operates in different countries and has a multilingual resource, it should be pointed, using special attributes, for which region and language some page is intended. As a result, the search engines may identify various versions of the site and provide users with the right variant.

Besides, these attributes help to avoid problems with Content Duplication, which may be a reason for pages indexing with similar content for a variety of regions.

For example, in the international on-line shop there will be the same descriptions of goods, however, the currency will differ for Great Britain and the USA. If you do not indicate the separate region for every page version, search systems can consider them duplicates.

Google recommends pointing out language and regional versions for multilingual sites for the following cases:
1
Only menu items and information at the bottom of the page are translated, and the basic information is in the main language. This option is most frequently used for sections with user content - on forums or feedback pages.
2
The site has one language with some regional differences. For instance, the English content is a little different for people from the USA, New Zealand, and Australia.
3
All project pages are in different languages. As an example, resource in Italian was translated into French and Spanish.
For specific geographic areas you can mark alternate pages versions in different languages by these ways:

  • by means of hreflang attribute HTML tag <link>:
hreflang in link HTML tag
  • by adding versions in HTTP headers:
hreflang in HTTP headers
  • in the sitemap.xml file:
hreflang in the sitemap
  • by adding <lang> attribute in the <html> tag:
hreflang in head tag

Rules for specifying languages and pages regions

  • Tags will be considered by search systems if all language pages have reciprocal links. At the same time, every page variation must have his own hyperlink;

  • it is necessary to indicate complete addresses, starting with HTTP or HTTPS;

  • page versions can be hosted on different domains;

  • hreflang attribute may contain the information only about language code or completed with region data, for which a specific page is created;

  • it is expected, what version will be displayed for the user, whose browser settings has language different from the presented resource. For example, a user who speaks Chinese is more likely to understand the page in English than in Ukrainian.

To indicate a default page, it can be used the optional value x-default with the following syntax:
<link rel="alternate" href="https://site.com/" hreflang="x-default" />
This parameter is used in the following cases:

  • if the project has IP-dependent pages, from which users are served to the appropriate language version of the site;

  • for pages, having the possibility of dynamic content choice on some languages;

  • for pages where there are a language and region selections.

How to use hreflang in <link> tag

Attribute hreflang is added to the section heading <head> and has the following syntax:
<link rel="alternate" hreflang="language code" href="URL-address" >
For instance, the syntax defining three alternative site versions on English, Ukrainian and Russian will be the following:
<link rel="alternate" hreflang="en" href="https://serpstat.com/" />
<link rel="alternate" hreflang="uk" href="https://serpstat.com/uk/" />
<link rel="alternate" hreflang="ru" href="https://serpstat.com/ru/" />
Links to all versions, including the home page are added to the header.

Google cannot recognize an appropriate language for the visitor based on the URL; it is important to indicate its code explicitly. In this case, users from Ukraine and England or visitors, speaking of these languages, reach necessary landing pages from search results. The information about the region and language of the user is defined by browser settings.

This way can be rather cumbersome for sites, which are translated into many languages. Adding a long code with all links negatively affects the performance of the project. Therefore, for such major projects, it may be preferable to use other ways of indicating the languages.

Using hreflang in HTTP headers

The informing search systems about page versions in different languages and optimised for certain regions can be with using HTTP headers. This is the preferable option for file optimization, which created not in HTML-format, but, for example, in terms of PDF-documents and other content.

The information in headers is written in the following way:
Link: <full URL of file on the first language>; rel="alternate"; hreflang="two-letter code of the first language", <full URL of file on the second language>; rel="alternate"; hreflang="two-letter code of the second language"

Adding hreflang to Sitemap

Besides, it can be used to indicate language and regional versions of Sitemap pages. The list of necessary links is added to this file as follows:
1
Firstly, it is necessary to write namespace correctly.
2
Then to add <URL> tag.
3
After it follows <loc> tag, which has the URL of the page.
4
Then all versions with homepage are specified together in <xhtml:link> tag, where language and region codes are indicated.
5
</URL> closing tag is placed.
6
After that, items 2-5 are repeated for all URLs with existing language versions.

Using lang attribute in <html> tag

An alternative method to inform a search system about the language of the page is to add lang in <html> tag. This attribute specifies the language for the whole page, including its title. If text passages in other languages are placed on the page, for them can be specified necessary meaning different from the set in <html> tag.

The example of syntax to set English language:
<html lang="en">
In order to set a certain language dialect, it is necessary to use BCP 47 specification coding. For example, es-419 code denotes Spanish used in Latin America and the Caribbean locations. In order to figure out the necessary codes, you can use the Language Subtag Lookup utility, which has access to a list of all language codes filtered by certain parameters:
Language codes in the Language Subtag Lookup utility
Personal demonstration
Our specialists will contact you and discuss options for further work. These may include a personal demonstration, a trial period, comprehensive training articles, webinar recordings, and custom advice from a Serpstat specialist. It is our goal to make you feel comfortable while using Serpstat.

Validation of multilingual project version

To check the correctness of typed language and regional data on the site, it is possible by using Flang validator, indicating the URL of the project and clicking "Validate now!":
Multilingual sites validator Flang
There is also another validator - hreflang.ninja, which works in the same way:
Multilinguality validator hreflang.ninja online
You can also use Serpstat Site Audit tool to check if everything is ok with the rel alternate hreflang attribute. After the process is completed, go to the All issues report. Here you can see if anything is wrong with hreflang and receive useful recommendations.
Serpstat audit displays hreflang in SEO issues
Advanced SEO Audit: A Complete Guide To All Stages Of The Analysis [Infographic]

FAQ

What is hreflang?

Hreflang determines which page the search engine will display to the visitor, depending on his native language and location.

How to set hreflang?

It could be set in HTML tag , by adding versions in HTTP headers, in the sitemap.xml file or by adding attribute in the tag.

How to change website language in html?

To set language of the page as English you should use the 'lang' attribute along with 'en' language code and apply this to the HTML element at the beginning of each page.

Why does hreflang matter for SEO?

If you did not specify the value of the hreflang tags or indicated them incorrectly, this could negatively affect the usability and ranking of your site.

Сonclusion

1
The setting of language and region on the pages of multilingual sites and projects will help visitors to go on relevant pages in search results.
2
Thanks to using lang and hreflang attributes, there is not just an improvement of user experience but also the exception of the problem of content duplication, which is important to SEO. Search systems even recognize pages with similar content as adapted to different regions.
3
Using hreflang x-default allows providing a universal page version. Users, living in countries and speaking languages, which are not defined on the site by hreflang, will be served on this page.
4
Specifying language, regional, and dialect codes, it is important to check their compliance with the specifications. It can be checked by offered above validators.
This article is a part of Serpstat Site Audit tool
SEO Audit in Serpstat
Conduct an audit of your site or page in one click and get a complete list of technical issues, ways to resolve them, and useful recommendations. Set up any convenient audit schedule and receive automatic email reports.
Create a project
Join us on Facebook and Twitter to follow our service updates and new blog posts :)

Speed up your search marketing growth with Serpstat!

Keyword and backlink opportunities, competitors' online strategy, daily rankings and SEO-related issues.

A pack of tools for reducing your time on SEO tasks.

Get free 7-day trial

Rate the article on a five-point scale

The article has already been rated by 1 people on average 5 out of 5
Found an error? Select it and press Ctrl + Enter to tell us

Discover More SEO Tools

Tools for Keywords

Keywords Research Tools – uncover untapped potential in your niche

Serpstat Features

SERP SEO Tool – the ultimate solution for website optimization

Keyword Difficulty Tool

Stay ahead of the competition and dominate your niche with our keywords difficulty tool

Check Page for SEO

On-page SEO checker – identify technical issues, optimize and drive more traffic to your website

Share this article with your friends

Are you sure?

Introducing Serpstat

Find out about the main features of the service in a convenient way for you!

Please send a request, and our specialist will offer you education options: a personal demonstration, a trial period, or materials for self-study and increasing expertise — everything for a comfortable start to work with Serpstat.

Name

Email

Phone

We are glad of your comment
I agree to Serpstat`s Privacy Policy.

Thank you, we have saved your new mailing settings.

Report a bug

Cancel
Open support chat
mail pocket flipboard Messenger telegramm