W3cubDocs

/Web APIs

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

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
lang 1 12 1 ≤12.1 3 18 4 ≤12.1 1 1.0 4.4 1

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/lang