Declaring language in HTML
Why you should declare the language of an HTML page
There are many reasons for declaring the language of an HTML page in the source code. First of all, it makes it easier for user agents to correctly display the text content of a web page. In addition, the language specification in the HTML code helps search engines to show the right search results to users from different countries. If the language of a page is not explicitly specified in the HTML code, search engines will try to determine its language based on other factors (see Section 2), but this can lead to misinterpretations.
In addition, you should also mark language changes within an HTML page, for example, to facilitate translation services work.
Check language declaration
Check the language declaration of your HTML page
Factors influencing the identification of language
As mentioned above, search engines have a few other options for determining the language of a web page if you don’t declare it in HTML code. For example, modern search engines like Google can use simple text analysis to recognize the language of the content on a web page and thus assign it to the correct country index. However, there might be a problem if there is little text content to analyze or even text in several languages on the same website.
Furthermore, search engines can use the server location or the domain extension to identify the language of a website, but this does not always lead to correct results. For example, a website could have a domain which ends in .de and a server which is also located in Germany, however individual pages on this site are written in English.
Thus, in order to avoid misinterpretations, you should always specify the language of a web page in the HTML code. In the next section, we will explain to you how this works.
How to declare language in HTML
The easiest way to set the language of a page is via the following lang attribute in the HTML element (HTML 5):
<html lang = "en">
You should always specify this lang attribute in the HTML element since it is inherited to all other elements as well, and thus also defines the language for text in the head area. This would not be the case if you used the lang attribute in the body element.
If parts of the text within a page are written in a different language, the lang attribute should be added to any element that contains such foreign language parts.
For pages that are delivered as XML, use the xml: lang attribute.
Search engines also understand outdated language information in the meta attributes of a web page such as
<meta http-equiv = "content-language" content = "en">
however, these should not be used.
To determine the right two-letter language code according to ISO 639-1, you can use the IANA language subtag registry. These codes can also be composed of two parts, the first part referring to the language and the second part referring to the country in which the language is spoken, e.g. "en-us" for American English.
If you have problems with declaring the language of your web page via a lang attribute, you can, for example, manually set the geographical orientation of your website for Google using Search Console (> Site Settings).
Options for structuring multilingual websites
If a website contains pages and content in different languages, e.g. if a company operates internationally, there are various ways to structure it.
For example, you could purchase a country domain for each country, e.g. example.de, example.es, example.it etc.
Another option would be to host each language version on a subdomain, e.g. de.example.com, es.example.com, it.example.com, and so on.
Alternatively, you can create a subdirectory for each language, with the major version of the site remaining in the root directory, e.g. example.com/es/ or example.com/it/.
For dynamic pages, it is also possible to add a lang parameter for the respective language to the URL, e.g. example.com/products.php?lang=es.