How to specify the language of the element's content in HTML?



The language of an element's content can be identified using the HTML lang property. Language code, which is used to specify the language of the displayed information, is the only value for this element.

Syntax

<p lang = “required language”>

Following are the examples…

Example

In the following example we are using lang property to specify the language of the element content.

<!DOCTYPE html> <html> <body> <h1>English</h1> <p lang="en"> The Best E-Way Learning. </p> <h2>french</h2> <p lang="fr"> Le meilleur apprentissage E-Way. </p> </body> </html>

Output

On executing the above script, it will display two texts in different languages as we mentioned in the script.

Example

Here, we have added content in French and Spanish as well.

<!DOCTYPE html> <html> <body> <h2>English</h2> <p lang = "en">This is demo text</p> <h2>French</h2> <p lang = "fr">Ceci est un texte de démonstration</p> <h2>Spanish</h2> <p lang = "es">Este es un texto de demostración</p> </body> </html>

Output

The output obtained after executing the script above is −


Advertisements