How to fix a missing page language
WCAG 3.1.1 Language of Page, level A. Rule html-has-lang in axe-core.
What is wrong
The <html> element has no lang attribute. Screen readers then fall back to the visitor's default voice, which may read French text with English pronunciation, or the reverse. Browsers also use the language for translation offers and for hyphenation.
Who it blocks
Screen reader users, and visitors who rely on automatic translation.
How to fix it
<!-- before -->
<html class="no-js">
<!-- after -->
<html class="no-js" lang="fr">
Use the code of the language the page is written in: en, fr, de, es, it, nl, pt, and so on. A region can be added, such as fr-BE. On a multilingual shop, each language version needs its own value; most platforms set it from the store language setting, which is the place to fix it.
Common mistakes
- Hard-coding
lang="en"in a theme used for every language. - Invalid codes such as
lang="english"orlang="fr_FR"(the separator is a hyphen). - Forgetting parts of a page in another language, which need their own
langon the element.
How the scan proposes a fix
The scan guesses the language from common words in the visible text, adds the lang attribute to the original <html> tag, and runs the same rule on a page built with it. Check the guess before using it.
Check your own pages for free
Drag this button onto your bookmarks bar: Scan with accessaudit. Then open a page of your shop and click the bookmark: a score and the three main defects appear in a few seconds. The check runs in your browser: no content of your page leaves it, only the scanner is downloaded from this site. Try it on a demo shop.