HTML

Internationalization Attribute


The lang attribute is the primary internationalization attribute in HTML. It specifies the language of the content within an element or the language of the entire document. This attribute is essential for accessibility and aids in proper rendering of text in various languages.

Here's how you can use the lang attribute:

 

Specifying Language for an Element:

You can specify the language for individual elements within your HTML document using the lang attribute.

<p lang="en">This is an English paragraph.</p>
<p lang="fr">Ceci est un paragraphe en français.</p>

 

Specifying Document Language:

You can specify the language for the entire HTML document in the <html> tag.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <!-- Your content here -->
</body>
</html>

In this example, lang="en" indicates that the document is written in English. This attribute helps screen readers and other assistive technologies provide the content in the correct language and pronunciation.

 

Nesting Language Attributes:

If the content within an element is in a different language than its parent, you can nest lang attributes to specify multiple languages within the document hierarchy.

<div lang="en">
    <p>This paragraph is in English.</p>
    <div lang="fr">
        <p>Ceci est un paragraphe en français.</p>
    </div>
</div>

In this case, the outer <div> is in English, while the nested <div> is in French.