CKTIS / HTML
HTML concept: language-and-direction
Content language and base text direction are separate inherited semantic properties used for pronunciation, hyphenation, glyph choice, and the Unicode bidirectional algorithm.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
language metadata + Unicode bidirectional base directionThe lang attribute must contain a valid BCP 47 tag or the empty value when language is unknown, and descendants inherit it. If XML syntax also supplies xml:lang, both values must match ASCII case-insensitively; the :lang() selector accounts for inherited language.
The dir attribute has ltr, rtl, and auto states. The first two explicitly set base direction, while auto derives it from the first strong character according to the element’s rules; digits and neutral punctuation do not decide direction.
The bdi element isolates an unknown-direction fragment from its surroundings, while bdo overrides the algorithm and requires explicit dir. CSS direction alone does not replace semantic metadata, and dynamic user names or titles should be isolated so they cannot reorder adjacent punctuation.
The example tests inherited language with :lang(ar), inherited direction, and two paragraphs using dir="auto". A first strong Latin character produces left-to-right direction, while a first strong Arabic character produces right-to-left direction.
Examples
<!doctype html>
<meta charset="utf-8">
<div lang="ar" dir="rtl"><span id="child">مرحبا</span></div>
<p id="latin" dir="auto">42 English العربية</p>
<p id="arabic" dir="auto">42 العربية English</p>
<output id="result"></output>
<script>
const child = document.querySelector("#child");
const latin = document.querySelector("#latin");
const arabic = document.querySelector("#arabic");
result.textContent = `inheritsLang=${child.matches(":lang(ar)")}; inheritedDir=${getComputedStyle(child).direction}; autoLatin=${getComputedStyle(latin).direction}; autoArabic=${getComputedStyle(arabic).direction}`;
</script>
Result
inheritsLang=true; inheritedDir=rtl; autoLatin=ltr; autoArabic=rtl
The executed example verifies inheritance and first-strong-character detection; it does not test a particular screen reader’s pronunciation or every Unicode Bidirectional Algorithm rule.