Language of Parts: Mark Foreign-Language Text
Also called: Language change, lang attribute on elements, Foreign-language passages
Definition
Language of Parts is WCAG success criterion 3.1.2. The human language of each passage or phrase in the content must be programmatically determinable – except for proper names, technical terms, words of indeterminate language and words that have become part of the surrounding language.
Language of Parts is the WCAG rule that text in another language than the rest of the page is marked in code. A German quote on an English page, a French product name with a description or the "Deutsch" entry in a language switcher get their own lang attribute. Screen readers then switch to the right pronunciation instead of reading foreign words with English rules.
What it means
WCAG 3.1.2 Language of Parts is a Level AA criterion of WCAG 2.2. It builds on Language of Page (3.1.1): the page declares its default language, and every passage or phrase in another language declares its own. Text without a marked language inherits the page language, so a page in one language passes automatically.
The criterion applies to longer passages and to single words. W3C names four exceptions:
| Exception | Example | Needs lang? |
|---|---|---|
| Proper names | A philosopher's name in an English text | No |
| Technical terms | Homo sapiens, hertz, habeas corpus | No |
| Words of indeterminate language | Words that belong to no single language | No |
| Words that became part of the surrounding language | "rendezvous" in English, "podcast" in French | No |
| A full sentence or quote in another language | A German phrase in an English article | Yes |
| Language names in a language switcher | "Deutsch", "Français", "Español" | Yes |
Marking the exceptions is not required, but W3C calls it good practice. When in doubt whether a borrowed word counts as part of the vernacular, check whether it is pronounced the same way in the surrounding language.
Who benefits? Screen reader users hear the right pronunciation, braille displays and voice browsers can apply the rules of that language, and browsers and translation tools treat the passage correctly. People with reading difficulties who use text-to-speech also rely on it.
Examples
<html lang="en">
…
<p>As the Austrians say, <span lang="de">"Schau ma mal"</span> – let's wait and see.</p>
<!-- Language switcher: each name in its own language -->
<ul>
<li><a href="/de" lang="de" hreflang="de">Deutsch</a></li>
<li><a href="/fr" lang="fr" hreflang="fr">Français</a></li>
</ul>
<!-- Not needed: proper name and vernacular word -->
<p>Our café near Mozartplatz offers a croissant breakfast.</p>W3C also shows a case of mixed languages: a link with an English title attribute contains the word "Español" in a span with lang="es". Only the Spanish text is marked, so the attribute stays English.
Mark quotes, slogans, song titles and whole sentences in another language with lang. Give every entry of a language switcher the language it is written in. Use valid language codes such as de, fr or es-MX.
Mark every borrowed word such as "kindergarten" or "café" as a foreign word. Don't use invalid codes like lang="german" or en_US – browsers can't read them. Don't rely on a flag icon alone to show the language of a link.
How to check Language of Parts
Questions
Do I have to mark every foreign word with lang?
No. Proper names, technical terms, words of indeterminate language and words that are part of the surrounding language are exceptions. Mark whole phrases and passages in another language; marking the exceptions too is optional good practice.
What is the difference between Language of Page and Language of Parts?
Language of Page (3.1.1, Level A) requires the default language on the html element. Language of Parts (3.1.2, Level AA) requires a lang attribute on passages that differ from that default.
Is lang the same as hreflang?
No. lang says which language the content of an element is in. hreflang on a link says which language the target page is in. A language switcher link can use both.
Do language names in a language switcher need lang?
Yes. W3C gives this exact example: "Deutsch" should be marked as German, "Français" as French. Otherwise an English screen reader reads them with English pronunciation.
Related terms
Language of Page: Declare the Default Language
Language of Page is WCAG success criterion 3.1.1. It requires that the default human language of each web page can be programmatically determined – in HTML through the lang attribute on the html element.
Read definition: Language of Page: Declare the Default LanguageMissing Lang Attribute: Error Explained and Fixed
A missing lang attribute means the html element of a page has no lang attribute, or an empty or invalid one. Browsers and screen readers then cannot tell which language the page is written in.
Read definition: Missing Lang Attribute: Error Explained and FixedScreen Reader: How It Reads Websites and What It Needs
A screen reader is assistive software that reads the content and controls of a screen aloud or outputs them on a braille display. It relies on the names, roles and states that a website exposes through the browser's accessibility tree.
Read definition: Screen Reader: How It Reads Websites and What It NeedsLink Purpose: Write Link Text That Makes Sense
Link purpose is what a link does or where it leads. Under WCAG 2.4.4, users must be able to tell it from the link text alone or together with its programmatically determined context, such as the surrounding sentence.
Read definition: Link Purpose: Write Link Text That Makes Sense