The HTML lang attribute specifies the language of an element's content.
Definition and Usage
➔ This is a global attribute and can be used on any HTML element.
➔ The lang attribute is mainly used inside the <html> tag, to specify the default language for the entire document.
➔ lang is suitable for assistive technologies that provide a significant user experience for people with visual impairments or reading difficulties.
Syntax
//In HTML
<!DOCTYPE html>
<html lang="en">
<!-- Document contents goes here. -->
<p>This is a paragraph in English.
<span lang="es"> Este es un párrafo en español. </span>
<span lang="fr"> Este es un párrafo en francés. </span></p>
</html>
//In JavaScript
<script>
//For the <html> element
document.documentElement.lang = 'en';
//For other specific element
const element = document.getElementById('id');
element.lang = 'en';
element.setAttribute("lang", "en-us");
</script>
Applies to
This attribute can be used on the following element.
| Attribute | Element |
|---|---|
| lang | Global Attributes |