HTML - lang Attribute



HTML lang attribute is global attribute that is used to define the language of an element's content.

In HTML documents, the <html> tag accepts the lang attribute, which is by default unknown. If you pass the value of the lang attribute, then the user will know that the content of this element is in this language, like English, Spanish, French, and so on.

The default value of lang is unknown; therefore, it is recommended to always specify this attribute with the appropriate value.

Syntax

<element lang  = "value" >

This attribute holds any valid language code.

Applies On

Since lang is a global attribute in HTML, all the tags in HTML support lang attribute.

Examples of HTML lang attribute

Below examples will illustrate the HTML lang attribute, where and how we should use this attribute!

Define french Language

In the following example, we are using the lang attribute along with elements to define the language of the content.

<!DOCTYPE html>
<html>

<body lang="fr">
   <p>
      This paragraph is English, but the 
      language is not specifically defined.
   </p>
   <p>
      This paragraph is defined as British 
      English.
   </p>
   <p>
      Ce paragraphe est défini en français.
   </p>
</body>

</html>

Define Multiple Languages on single Document

Considering the another scenario, where we are going to use the lang attribute with arabic and hindi. Arabic languages text direction is changed as it should start from right using dir attribute.

<!DOCTYPE html>
<html>

<body>
   <p lang="ar" dir=rtl >
      هذا الفقرة محدد باللغة العربية.
   </p>
   <p lang="hi">
      यह पैराग्राफ हिंदी में परिभाषित है।
   </p>
</body>

</html>

Supported Browsers

Attribute Chrome Edge Firefox Safari Opera
lang Yes Yes Yes Yes Yes
html_attributes_reference.htm
Advertisements