Features

Ensure every HTML document has a lang attribute

Rule ID: html-has-lang User Impact: serious Guidelines: WCAG 2.0

Ensure that the <html> element includes a lang attribute to specify the primary language of the document.

About This Rule

This rule ensures that the <html> element contains a valid lang attribute, facilitating proper language identification for assistive technologies and enhancing accessibility for multilingual users.

Why It Matters

Screen readers and other assistive technologies rely on the lang attribute to determine the language of the content, enabling accurate pronunciation and interpretation. Without this attribute, users may experience incorrect pronunciation, leading to confusion and a diminished user experience.

How to Fix

To specify the primary language of your document:

  • Add a lang attribute to the <html> element with a valid language code. For example, for English:
    Copy code
    
    <html lang="en">
      <!-- document head and body -->
    </html>
          
  • For regional dialects, use appropriate language codes, such as "en-US" for American English or "fr-CA" for Canadian French.
  • If the document contains sections in different languages, specify the language for those sections using the lang attribute on the relevant elements:
    Copy code
    <p>This is an English paragraph.</p>
    <p lang="es">Este es un párrafo en español.</p>
  • For languages written right-to-left, also include the dir attribute:
    Copy code
    <p lang="ar" dir="rtl">نص باللغة العربية هنا</p>

Other Rules

Interested in other web accessibility rules? Please see these other rules: