Наші добровольці ще не переклали статтю цією мовою: Українська. Долучайтеся й допоможіть це зробити!
Ви також можете прочитати цю статтю іншою мовою: English (US).

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 the Tags for Identifying Languages (BCP47) IETF document. 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.

Syntax

var languageUsed = elementNodeReference.lang; // Get the value of lang
elementNodeReference.lang = NewLanguage; // Set new value for lang

languageUsed is a string variable that gets the language in which the text of the current element is written. NewLanguage is a string variable with its value setting the language in which the text of the current element is written.

Example

// 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";
}

Specification

Specification Status Comment
Document Object Model (DOM) Level 2 HTML Specification
The definition of 'lang' in that specification.
Obsolete  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
langChrome Full support 1Edge Full support 12Firefox Full support 1IE ? Opera Full support YesSafari Full support 6WebView Android Full support 4.4Chrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

Мітки документа й учасники

Зробили внесок у цю сторінку: mdnwebdocs-bot, fscholz, xfq, cvrebert, teoli, kscarfone, Sheppy, ethertank, tregagnon, Brettz9, Mgjbot, Ptak82, GT, Dria, Callek, JesseW
Востаннє оновлена: mdnwebdocs-bot,