W3cubDocs

/Web APIs

HTMLElement: lang property

The HTMLElement.lang property gets or sets the base language of an element's attribute values and text content.

The language code returned by this property is defined in RFC 5646: Tags for Identifying Languages (also known as BCP 47). Common examples include "en" for English, "ja" for Japanese, "es" for Spanish and so on. The default value of this attribute is unknown. Note that this attribute, though valid at the individual element level described here, is most often specified for the root element of the document.

This also only works with the lang attribute and not with xml:lang.

Value

A string.

Examples

js

// 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 Standard
# dom-lang

Browser compatibility

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

© 2005–2023 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