HTMLElement: lang property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Thelang property of theHTMLElement interface indicates the base language of an element's attribute values and text content, in the form of aBCP 47 language tag. It reflects the element'slang attribute; thexml:lang attribute does not affect this property.
Note that if thelang attribute is unspecified, the element itself may still inherit the language from its parent. However, that inherited language is not reflected by this property's value.
In this article
Value
A string. Common examples include "en" for English, "ja" for Japanese, "es" for Spanish and so on. If unspecified, the value is an empty string.
Examples
js
// this snippet compares the base language and// redirects to another URL based on languageif (document.documentElement.lang === "en") { window.location.href = "Some_document.html.en";} else if (document.documentElement.lang === "ru") { window.location.href = "Some_document.html.ru";}Specifications
| Specification |
|---|
| HTML> # dom-lang> |