A: < html> must have a lang attribute (WCAG 3.1.1)
html-has-lang
Ensure that every HTML document has a lang attribute.
This means
The root element <html> needs a lang attribute with a valid BCP-47 language code (e.g., de, de-DE, en). Without or with an incorrect value, screen readers, translations, and spell checking cannot reliably recognize the page language.
Impact
Without the correct language setting, content is pronounced incorrectly, hyphenation and autocorrect do not work properly, and users lose orientation. Additionally, the risk of WCAG violations increases.
Recommendation
-
Set the primary language of the page on <html> (e.g.,
lang="de"). -
Mark sections in other languages additionally on the respective element (e.g.,
lang="en"for a quote). -
Use valid BCP-47 tags (hyphen, not underscore; no placeholders like
xx). -
No conflicting information (no empty
lang="", no differingxml:lang). -
Update the attribute when dynamically switching languages.
Example
Problematic
<!doctype html>
<html>
<head><title>Contact</title></head>
<body>Welcome</body>
</html>
<!-- empty or invalid -->
<html lang=""></html>
<html lang="de_DE"></html>
<html lang="german"></html>
Better
<!doctype html>
<html lang="de">
<head><meta charset="utf-8"><title>Contact</title></head>
<body>
<p>Welcome to our site.</p>
<blockquote lang="en">Accessibility improves everyone’s experience.</blockquote>
</body>
</html>
Related WCAG criterion:
WCAG 3.1.1 - Language of Page