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.
The lang
property of the HTMLElement
interface indicates the base language of an element's attribute values and text content, in the form of a RFC 5646: BCP 47 language identifier tag. It reflects the element's lang
attribute; the xml:lang
attribute does not affect this property.
Note that if the lang
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.
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
// this snippet compares the base language and
// redirects to another URL based on language
if (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 |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
lang |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support