Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

HTML term or value: lang

The `lang` attribute declares the natural language of an element and its contents so browsers and assistive technologies can select appropriate pronunciation and typographic rules.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<article lang="fr">…</article>

A non-empty lang value must be a valid BCP 47 language tag such as fr or pt-PT; the empty value is permitted only for an explicitly unknown language. Absence inherits language from an ancestor.

In an HTML document, lang="" declares the language unknown; XML serialization uses xml:lang, and when both attributes occur their values must match ASCII case-insensitively. Set the document default on the root and override it only for passages in another language.

Language affects screen-reader pronunciation, spelling, hyphenation, and quotation marks among other behavior. The :lang() selector accounts for inherited language, whereas [lang] finds only elements carrying their own attribute.

In the example, x.lang returns "" because the paragraph has no own attribute; closest("[lang]") finds the inherited fr, while document.documentElement.lang exposes the missing root declaration. This separates reflection from effective language.

Examples

<!doctype html><meta charset="utf-8"><article id="a" lang="fr"><p id="x">Bonjour</p></article><output id="result"></output><script>result.textContent=`own=${x.lang}; inheritedFrom=${x.closest("[lang]").lang}; document=${document.documentElement.lang}`;</script>

Result

own=; inheritedFrom=fr; document=

The executed example verifies that the IDL property reflects only the element’s own attribute even though its contents inherit language from the nearest ancestor.

Sources