As you well know, the must haves on every web page include the standard header information that identifies the html version, the page title, and keywords, but there seems to be some debate as to the use of specifying the document content language on web documents. Some consider it unnecessary and that it should be a suggestion only, their point being that most browsers will pick up the native language based on the location where it is being hosted. In particular, if you provide multilingual content in your web documents you should continue to declare the main language attribute for that content. It is considered a best practice to declare the document language in your html code, and is a Do on my list of Do's and Don'ts.
The lang attribute assists browsers in rendering the language content; it also aids in text-to-speech devices, speech synthesizers, glyph variants for high quality topography, setting quotation marks correctly, and spell checkers among other useful purposes. When abbreviations and natural language changes for that matter are not identified with the lang attribute, the language may be indecipherable when machine-spoken or brailled. Therefore, visitors with disabilities will not be able to render your documents successfully either way.
In addition, if you are not aware, all Federal agencies must follow Section 508 Standards as specified in the amended Rehabilitation Act of 1973 and require Federal agencies to make their electronic and information technology (EIT) accessible to people with disabilities; you can learn more about the standards at Section508.gov.
The lang attribute specifies the base language of the documents elements, content, and attribute values, for example, and there is no default value.
To declare the language as an html attribute, the syntax is represented as:
lang=[primary language code - sub-code]For example it can be declared as the HTML attribute,
<html lang="en">,where "en" is for English, or <html lang="en-ca">, where "en-ca" represents English in Canada. The primary language code is represented by the two-letter abbreviations tag as stipulated in ISO standard 639 "Code for the representation of names of languages" [ISO 639] (e.g., ar=Arabic, en=English, fr=French, de=German, es=Spanish, zh=Chinese). And the country sub-codes also use a two-letter abbreviation tags (e.g., be=Belarus, eg=Egypt, jm=Jamaica, tw=Taiwan, us=United States). For a more complete list of the language codes and country sub codes check out the w3Schools HTML Language Code Reference, and the MSDN Language Codes.
The language can also be declared in the document head as metadata, as shown in the example:
<meta http-equiv="Content-Language" content="ar,en,fr,de,sp,zh" />
Another way to declare the language would be to insert it within specific elements of the document. For example, if you needed to insert a short quote or a few sentences of text in a foreign language, you could add the lang attribute into that paragraph or division. For example: <p lang="fr"> for specifying the paragraph as French language, or <div lang="de"> for declaring the division as German language.
You can add the declaration to other elements, such as the example below:
<p>The Spanish translation for the phrase "good morning" is <em lang="es">
In my next Quick Tip, I will review Character Encoding, as it does go hand-in-hand with the document language declaration.
Ryan has performed in a broad range of technology support roles for electric-generation utilities, including nuclear power plants, and for the telecommunications industry. He has worked in web development for the restaurant industry and the Federal government.