Language declaration in website code

08/03/2009

Language declaration in website code

Should websites use the ‘lang’ html attribute or the ‘Content-language’ meta tag?

When creating International websites it is important to define the language used in the files and there are several methods available. These are:

  • The language attribute (lang or xml:lang) on the html tag
  • The Content-Language attribute of the meta tag
  • The Content-Language parameter sent with the website header

There are important differences between the above methods of defining website HTML language.

The html language attribute defines the text-processing language from the server, and there should therefore be only one value for this. It is used by voice browsers and spell checkers to handle the text in the correct language.

The metadata ‘Content-Language’ should be used to specify the languages for the intended audience, and this may contain multiple languages. For example on some website which Cornish WebServices have produced some pages are written in multiple languages.

Using the website header for declaring the language of the page is less useful for many reasons, including the fact that if the document is not read from a server this information will not be available which is not good practice.

The best practice advice for declaring language in a website page is therefore:

  1. 1. Define the main language in the lang and xml:lang attributes of the html tag
  2. 2. Where a webpage contains multiple languages define these within a <meta> tag using the ‘Content-Language' parameter.

Examples of using the above language declarations would be:

<html lang="fr" xml:lang="fr"> 
for  French webpage

and

<html lang="fr" xml:lang="fr"> 
<meta http-equiv="Content-Language" content="fr, de, it"/>
for a French webpage with sections also in German and Italian.

← Back to Index

Email usTel: +44 (0)330 555 4680
X

Our site uses cookies to help provide you the best experience. By continuing to browse the site you are agreeing to our use of cookies.
Find out more about cookies and how to change your cookie settings in your browser.