HTMLElement: lang プロパティ
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.
HTMLElement.lang
プロパティは、要素の属性値とテキストコンテンツの基本言語を取得または設定します。
このプロパティによって返される言語コードは、 RFC 5646: Tags for Identifying Languages (BCP 47 とも呼ばれる) で定義されています。 一般的な例には、英語の "en"、日本語の "ja"、スペイン語の "es" などがあります。 この属性の既定値は unknown
です。 この属性は、ここで説明する個々の要素レベルで有効ですが、ほとんどの場合、文書のルート要素に対して指定されます。
これも lang
属性でのみ機能し、xml:lang
では機能しません。
値
文字列です。
例
js
// このスニペットは基本言語を比較し、
// 言語に基づいて別の URL にリダイレクトするものです
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 |
---|
HTML # dom-lang |
ブラウザーの互換性
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
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.