STR-006a Mark text in another language than the text around it with its own lang attribute
- Level
- Rule
- Verdict
- Requirement
- Area
- Page structure
- Status
- proposed, version 1.0.0
Rule
When a passage, phrase or word is in another language than the text around it, put lang with that language's tag on the element that holds it, such as language picker entries written in their own languages. Proper names, technical terms, words of unclear language and words the surrounding language has taken in need none.
Examples
Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.
Do: Each entry carries its own language
aria-current, and the trigger now reads Language: Polski with lang="pl" on the name. English needs no lang in an English page.Don't: Entries in their own languages, no lang
Don't: Only hreflang on the links
hreflang names the page it leads to, not the language of the link's own text, so the readout shows no lang.Do: A review in Spanish, with an English phrase
Reviews
La cena fue excelente, un auténtico Sunday roast con vino de la casa.Mariana, table for four
lang="es", and the English phrase inside it switches back with lang="en".Don't: A French description shown unmarked
About this dish
Un ragoût lent d'agneau, servi avec des haricots blancs et du romarin.
Description not yet translated into English.
Why
A screen reader reads everything in the page's language unless the code says otherwise. In an English page, an unmarked "Português" is read with English sounds, and a quoted paragraph in Spanish comes out as a string of wrong syllables. The person may not even notice that the language changed, only that the text makes no sense. Browsers use the same marking to choose glyphs: Chinese, Japanese and Korean characters take different shapes depending on the declared language.
This is a requirement. WCAG 2.2, 3.1.2 Language of Parts asks that software can tell the language of each passage or phrase, with the four exceptions this rule names (Understanding 3.1.2). The Working Group's technique is lang on the element whose content is in the other language, with a valid tag (H58). Text with no marking takes its language from the elements around it and, in the end, from html (STR-006), so a page in one language meets this rule with no extra work. Café on an English menu is English, and so is déjà vu in an English review; only a deliberate switch to French is marked.
Do
- The booking app Larkspur is in English and offers Polish, Portuguese and Korean. Its language picker is a shadcn
DropdownMenubuilt from{ code, label }entries. EachDropdownMenuItemreads Polski, Português or 한국어 and haslang={code}. Where an item is a link to that language's version, it also hashreflang={code}. - Mark the current language's entry and the picker's trigger too, whenever they show a language name that is not the page's own. In the English view, English needs nothing; in the Polish view, it gets
lang="en". - When the whole label is in that language, put
langon the element that holds it, such as theaor theDropdownMenuItem, not on aspaninside it. A screen reader that reads a control's name may lose a language change inside it. - In an item that mixes two languages, such as Polski (Polish) in an English page, mark only the part that differs:
<span lang="pl">Polski</span> (Polish). A label in one language is simpler. - On the page Reviews, a guest's review in Spanish sits in a
blockquote lang="es". An English phrase inside it switches back with its ownlang="en". - When content comes from data that records its language, such as a product description shown in French because no English translation exists yet, put that language on the element that shows it. If the language is not known, do not guess; leave the text unmarked.
- When a part is marked with
langand its menus or dialogs render in a portal, putlangon the portalled content as well, or on the text itself. - Our own advice, not part of 3.1.2: write each entry in the language picker in its own language, Polski and not Polish, so a person who cannot read the current interface still finds theirs. Also our own advice: a flag may sit beside the name, never replace it. A flag that carries meaning needs a text alternative (STR-005).
- Our own advice: keep an
aria-labelin the same language as its element. Its text cannot carry a language of its own, so a name in another language goes in visible text marked withlang. - Our own advice: mark a name or borrowed word when a screen reader would mangle it badly, especially one from another writing system.
Don't
- Render the picker's entries Polski, Português and 한국어 in an English page with no
langon any of them. - Rely on
hreflangalone. It names the language of the page the link leads to, not of the link's own text. - Use a country code as a language:
sefor Swedish,ukfor British English orcnfor Chinese. Swedish issv, British English isen-GBand Chinese iszh. - Show an untranslated French description in an English page without marking it.
- Wrap every brand name, product name or code identifier in a
langspan.
Exceptions
- The four in the criterion. Proper names of people, places, brands and products; technical terms; words whose language cannot be told; and words that have become part of the surrounding language, such as borrowed words found in its dictionaries.
- The page's main language. The language of the whole page is set on
html, as STR-006 says. - Neighbouring rules. The accessible name of a picker's trigger still contains its visible text (ACT-001b). A flag used as the only label needs a text alternative (STR-005). When the picker shows which language is current, say so in code too, for example with
aria-currenton that entry; NAV-002a covers the current page in navigation.
Verdict
Requirement. Only the judges decide; the expert witnesses are shown but do not vote. How verdicts work
| Source | Role | Stance | Page |
|---|---|---|---|
| WCAG 2.2 | Law | Requires | 3.1.2 Language of Parts |
| WCAG 2.2 | Law | Supports | 3.1.1 Language of Page |
| Material Design | Judge | No position | |
| Apple Human Interface Guidelines | Judge | No position | |
| Carbon Design System | Judge | No position | |
| GOV.UK Design System | Expert witness | Supports | Language navigation |
| Nielsen Norman Group | Expert witness | No position |
Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.
History
- Version 1.0.0, : First version.
Last checked against the other rules for conflicts on .
More in Page structure: 7 rules and 1 guideline · All rules
Justified is an independent project. It is not affiliated with, sponsored or endorsed by the organisations whose guidance it cites. Read the full statement.
Apple is a trademark of Apple Inc., registered in the U.S. and other countries and regions.