Search topics
Pages read aloud in the wrong language
A shared layout hardcodes lang="en", so a Spanish page is read aloud with English pronunciation rules.
lang="en" The problem
Screen reader and braille users hear a page read with the wrong language's pronunciation, which can make it hard or impossible to understand
An outdoor shop has an English site and a Spanish one. A screen reader user opens the Spanish product page for a pair of hiking boots. The heading says "Botas de montaña", but the screen reader reads it as "BOH-tass dee mon-TANNA", with English vowels and stresses, and the description that follows is no easier. They know Spanish well; they cannot follow it read like this.
The site's shared layout starts with <html lang="en">, written once when the site was English only. When the Spanish version was added, the translation library swapped the words on each page, but nothing touched the lang attribute. Screen readers, read-aloud tools and braille translators use that attribute to pick a voice and pronunciation rules, so they read every Spanish page as English. WCAG 3.1.1 asks that the default human language of each page can be programmatically determined; here it can be determined, and it is wrong, which fails the same way as missing.
The failure follows the translation: the English pages are fine, so a team that tests only in its own language never hears it. It also reaches beyond assistive technology. Browsers use lang to offer translation, choose fonts and hyphenation, and apply quotation marks, so a Spanish page marked as English may be offered a translation "from English" and hyphenate wrongly.
3 of 10 groups affected
- No vision (affected)
- Low vision (affected)
- Colour vision (not affected)
- No hearing (not affected)
- Hard of hearing (not affected)
- No speech (not affected)
- Motor (not affected)
- Reach, strength (not affected)
- Cognitive (affected)
- Seizures (not affected)
- Without vision Screen readers choose a voice and pronunciation rules from lang. With the wrong one, Spanish words are read as if they were English, and braille displays can apply the wrong contractions.
- Limited language, cognitive and learning abilities People who listen to text with read-aloud tools to help them read hear garbled speech, and the support they rely on stops working.
- Limited vision People who use a screen reader alongside magnification, or browser read-aloud, hear the same wrong pronunciation.
axe's html-has-lang and html-lang-valid check that the attribute exists and that its value is a real language tag. lang="en" on a Spanish page passes both, so a common form of this failure, the wrong language rather than a missing one, goes unreported. A tool has to detect the language of the text and compare it. The usual page checks don't. Readout does when Chrome has its built-in language detector, and lists a mismatch for a person to check rather than as a failure, since a detector can misread short or mixed text. A coding assistant asked to "add a lang attribute" often writes lang="en" into the shared layout, which fixes the scan and keeps the failure on every translated page. Listen to each language version, or at least compare its lang with its text.
What the checkers report
- axe DevTools
- <html> element must have a lang attribute
- <html> element must have a valid value for the lang attribute
- HTML elements with lang and xml:lang must have the same base language
- Lighthouse
<html>element does not have a[lang]attribute<html>element does not have a valid value for its[lang]attribute.<html>element does not have an[xml:lang]attribute with the same base language as the[lang]attribute.
- WAVE
- Language missing or invalid
Try it
Listen to the Spanish product page
Press Listen on each part to hear it with the voice its lang picks, if your device has one; the panel shows the voice and how it sounds. Switch language and listen again.
Broken Can you fix this?
<html lang="en"> Botas de montaña
Impermeables y ligeras, para todo el año.
Kept me dry for three days of rain.
The fix
Keep the html lang set to the language the page is in
<!-- app.html, the shared layout --><html lang="en">What is wrong2 points
- The Spanish page is read with English pronunciation, because the page says it is English.
- That claim comes from the shared layout, which writes
lang="en"on every page, the Spanish ones too.
The template sets lang from the page's locale
<!-- app.html, rendered on the server for each request --><html lang="{locale}"> <!-- "es" on /es/ pages, "en" on /en/ -->How it is fixed2 steps
- Render
langin the shared layout from the page's locale: "es" on /es/ pages, "en" on /en/. Each page arrives with the language it is written in, before any script runs. - Give the English review its own
lang, so it keeps English pronunciation on the Spanish page (see Implementation decisions).
This fixes the Before and passes 3.1.1.
Both pass 3.1.1. When each language has its own URL and the server renders the page, set lang in the template from the locale in the URL: there is no script to forget. When a language switcher changes the words in the browser, the server's value is only right for the first load, so the code that changes the locale must set document.documentElement.lang too; most i18n libraries have a hook or an option for it. Many sites need both, a server value for the first load and a client update for the switch.
Use the shortest tag that is right: en, es, ja. Add a region only when the text differs by region, such as pt-BR or zh-Hant for traditional Chinese. Some codes that look right but are not valid, and that html-lang-valid reports on the html element.
englishorspanish: use the code, not the name;es_ES: tags use a hyphen, not the underscore that some locale systems print;jporcn: these are country codes; the language codes arejaandzh.
Templates copied from old XHTML often carry xml:lang beside lang. In an HTML page it does nothing, so delete it; if it stays, it must match lang exactly; axe reports html-xml-lang-mismatch when the two disagree on the base language.
A passage in another language inside the page, such as the English review or the switcher's "Español" link, needs a lang of its own as well. That is a separate criterion, 3.1.2 Language of Parts, covered in passages in another language read with the wrong voice; the fixes above mark the review so that fixing the page doesn't move it to the Spanish voice. When content is translated by a service in the browser, the service may update lang itself; check whether it does.
Verify the fix
5 checks, no mouse.
Test with: Screen reader
Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat when a language is added.
How screen readers handle lang
Limits
This is a starting pattern, not a guarantee for every application. Screen readers switch voices only when a voice for that language is installed; that is outside your control, but the markup must still be right. Test each language version of your real pages, with someone who reads that language if you can.
This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.
References
EaseWeb service
Fixed it? Keep it from coming back.
I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.