← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

HTML lang Attribute

accessibility Beginner

Also Known As

lang attribute html language page language language declaration bcp47 xml:lang

TL;DR

The lang attribute on <html> declares the page's primary language — required for screen readers to select the correct voice profile and pronunciation rules, and for WCAG 2.1 compliance.

Explanation

The lang attribute on the <html> element is one of the highest-impact, lowest-effort accessibility improvements. Screen readers (JAWS, NVDA, VoiceOver, TalkBack) use it to select the appropriate voice engine — without it, the reader uses its default language, producing incomprehensible pronunciation for content in another language. The value must be a valid BCP 47 language tag: 'en' for English, 'en-GB' for British English, 'fr' for French, 'de' for German, 'pl' for Polish. For multilingual pages, individual sections can override with lang on a specific element (<blockquote lang='fr'>) — this allows the screen reader to switch voice mid-page. WCAG 2.1 Success Criterion 3.1.1 (Language of Page) is Level A — the minimum accessibility conformance level. Missing lang is both a WCAG A failure and a Lighthouse accessibility score deduction.

Common Misconception

The lang attribute only matters for non-English sites — English-language screen reader users are also affected when visiting pages without lang because the reader must guess the language; additionally, browser translation features and spell checkers rely on lang.

Why It Matters

A Polish user visiting a Polish-language site without lang='pl' will hear their screen reader attempt to pronounce Polish words using English phonology rules — the result is completely unintelligible and the page is effectively inaccessible.

Common Mistakes

  • Omitting lang entirely — the most common mistake, fails WCAG 3.1.1 Level A.
  • lang='en' on a non-English page — setting the wrong language is worse than omitting it; the screen reader pronounces every word with the wrong phonology.
  • Using an invalid language tag (lang='english', lang='EN-us') — BCP 47 subtags are case-sensitive; the primary tag is lowercase, the region tag is uppercase (lang='en-GB', lang='zh-Hant').
  • Setting lang on <body> instead of <html> — must be on the root <html> element per WCAG specification.

Avoid When

  • Do not set lang to a language that doesn't match the page content — wrong lang is worse than missing lang for screen reader users.

When To Use

  • Always — every HTML page must have lang on the <html> element.
  • Add lang on specific elements when a section of the page is in a different language from the page default.

Code Examples

✗ Vulnerable
<!-- Missing lang — screen reader guesses language -->
<html>
  <head><title>Strona główna</title></head>
  <body>Witaj na naszej stronie...</body>
</html>
✓ Fixed
<!-- Correct lang on root html element -->
<html lang="pl">
  <head><title>Strona główna</title></head>
  <body>
    Witaj na naszej stronie...
    <!-- Inline language change for foreign-language quote -->
    <blockquote lang="en">"To be or not to be"</blockquote>
  </body>
</html>

Added 6 Apr 2026
Views 19
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 1 ping S 0 pings S 1 ping M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 2 pings T 1 ping F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Google 7 ChatGPT 1 Perplexity 1 Ahrefs 1 Meta AI 1
crawler 10 crawler_json 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Low
⚡ Quick Fix
Add lang='en' (or appropriate BCP 47 code) to the opening <html> tag
📦 Applies To
html web
🔍 Detection Hints
Missing lang attribute on <html> element
Auto-detectable: ✓ Yes lighthouse axe wave webhint
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: File

✓ schema.org compliant