Declaration of languages is very important for your content but is also good for Google search engine.
When you create a new domain this helps search engines detect language of your website which is important for your specific region. For general search, English will work the best.
On the other hand, when trying to rank on local Google, you need to use language that is common for that country.
In any case, it is something you need to do before anything else.
Main things a web user has to know
Besides helping search engines, there are other benefits when you have declared language:
- It shows the proper font
- It can be used to convert text to speech (for example, UK English instead of simply English)
- Documents will be shown in natural language
- Browser can use it for dictionary
How to declare HTML language attribute properly?
Language attribute and HTML always go together; HTML element always has to use a language tag which will also be added to other attributes by default.
If there is an article or some other type of content on a page with different language from that which HTML element uses, people have to use attributes on surrounding elements.
Even if you declare HTML language attribute in the right form, you still might encounter issues especially if you have a multi-annual text.
How to add the right HTML attribute?
For HTML, lang attribute is a must.
Here is how you set code for English language:
In some cases you will require several languages. These are called polyglot pages and they require both xml:lang and lang tags whenever you wish to add a language. You don’t need xml:lang tag when you deal with HTML. However, due to lang part of the attribute, it will still be recognized by various browsers.
What if attribute values and element use different languages?
One of the best examples for this is when you have a multilingual site. While website may be based on English as the primary language, it also may list some other language. These languages may be shown in their original version that is, by using language’s letters and spelling. Such small changes will be important for foreigners as may not be able to read link to languages. By including this language option in their native tongue, they can recognize it and switch it whenever.
Things which you can skip
There are certain things that are more of waste of time than anything but I will mention them anyway.
- Please have in mind that CSS cannot be used for language declaration
- Doctype may be confusing for some users; you may notice EN tag but this doesn’t refer to language of a document but instead language of schema
Extra Tips for Encoding
Instead of UTF-8, webmasters can use any character set from IANA character sets. However, no browser understands all of them.
It is highly recommended that for a better chance of browser encoding recognition, a more widely character encoding should be used.
Language should always be in the center of attention if you’re running a multilingual site.
With guidelines that I mentioned in previous chapters, there shouldn’t be any issue to declare HTML language attribute properly.
Have you had any issues when declaring languages for your site? How did you resolve them?