Language in HTML means declaring or making an attribute in an HTML document for the specific language(s) in which you publish your content on a website or page. The language attribute in HTML is composed of two parts, namely the HTML tag or <html>tag and the language part which is abbreviated as lang.
So, when declaring the language in the HTML document, you must place the lang attribute inside the HTML tag, so search engines and screen readers can see it.
ISO 639-1 language codes and country reference codes
ISO 639-1 language codes dictate the short version or code for each language. Looking at the example above, Danish was abbreviated as “da”. However, the ISO 639-1 language codes are particularly important when declaring two-part languages in HTML, as codes differ even if, at first glance, they represent the same language.
For instance, the OSP code for the English language is “en”. But, if we wanted to specify that we use US English, the country reference codes would be ‘US’. At the same time, for British English, the abbreviation would be ‘GB’. So the end result would be “en-GB” or “en-US” depending on our preferences.
Why is language in HTML declaration important?
First, search engines display results that correspond to the language settings of each user in their specific countries. Therefore, they use the language attribute to filter the search result based on those settings. Also, browsers use the language declarations to properly show the content of a website page. But, more importantly, declaring the language in the HTML is essential when it comes to UX and accessibility, especially for multilingual sites.
Declaring the language in HTML helps screen readers to automatically pick the right language mode for the user. One should also consider language translation services and indicate in the HTML page source code any language changes. If the language in HTML is not declared, the search engines will try to figure out in some other way, but the results may not be up to scratch.
Fun things to remember about language in HTML declaration
One can make the language declaration in any HTML element. For instance, the whole webpage can be in Danish but then have a paragraph in the English language. So in this case, we declare the language in the opening <html> tag as we should, then again in the <p> tag.
While we have to declare the language in HTML inside the <html> tag using the correct country code, if the language ins use is English, this is an exemption. Meaning that if our website is in English, we do not have to declare the language unless we want to specify the dialect – US or GB.
What happens if the language in Html is not declared?
Search engines can detect language on a website page through domain extension, server location, and text analysis of the content on a website page. However, these methods have a caveat – for instance, text analysis on a webpage is prone to fail if a website page has more than one language or there are more images or code than text – low text to Html ratio.
What about server location and domain extensions? Most hosting companies use servers all around the globe, outside their country or even region. So what happens of the server is located in the US, and the domain extension is .us, but the text is in Spanish? In both scenarios, without a language declaration in HTML, a misinterpretation of the language is inevitable.
So if you want your website and content to reach your users properly, it is highly recommended that you declare your language in the HTML document. More importantly, you wll get extra golden points fro search engines for having an accessible website. It’s all wins for you, and at such a low hassle.