Primary Language Attribute in HTML

This article explains how to use the language attribute in HTML.  


Introduction

HTML allows you to specify the natural language of your HTML document using the lang attribute.  Using the lang attribute will allow you to display language or dialog specific content to your viewers based on their web browsers default language setting.  In addition, the language attribute can also help search engines index your web page.


 

Primary Language Codes

 

Defining primary language(s) in the meta element

In a single HTML document you can declare multiple primary languages but only one base language.  Always define the languages you will be using in the meta element.  

<meta http-equiv="content-language" content="en">

The first attribute in the content value corresponds to the base languages and may be followed by a comma delimited list of additional primary languages.  Let's look at an example.  Let's say our HTML document has a base language of English, but also contains French.  Since English is the base language I must place it first followed by the primary language code for French.

<meta http-equiv="content-language" content="en,fr">


 

Primary language Codes Table

Language Code
Arabic ar
Chinese zh
Dutch nl

English

en
French fr
German de
Greek el
Hebrew he
Hindi hi
Italian it
Japanese ja
Portuguese pt
Russian ru
Sanskrit sa
Spanish es
Urdu ur

 

Defining primary language(s) blocks inside your web page 

The primary language attribute may be added to the tag that surrounds a block of text.  For example, <body lang="en"> can be used to indicate that the primary language for text declared inside the body is English.  In contrast, <p lang="fr"> may be used to indicate the primary language for text contained within a specific paragraph is french. 




Primary Language Subcodes

You may specifiy a specific dialect by appending a specific subcode to any given primary language code.  This is done by appending ("-" + subcode) to the primary language code.  

The version or dialect of the English language used in the United States of America is specified by using the "us" subcode.  Applying this to the primary language code "en" for English yields "en-us".  Returning to an earlier example, we would arrive at the following statement.

<meta http-equiv="content-language" content="en-us,fr">

 

     

 

Home About Development Consulting Services Contact