---
title: Valid lang Attribute Values | Accessibility Rule
description: lang attribute must have a valid value
source_url:
  html: https://testingbot.com/support/accessibility/web/rules/valid-lang
  md: https://testingbot.com/support/accessibility/web/rules/valid-lang/index.md
---
# Ensure lang attributes have valid values

Rule ID: valid-langUser Impact: seriousGuidelines: WCAG 2.0

The `lang` attribute in HTML specifies the language of the document's content. It's crucial to assign a valid language code to this attribute to enhance accessibility and ensure correct pronunciation by screen readers.

## About This Rule

This guideline ensures that the `lang` attribute has a valid value, enhancing accessibility for users who rely on assistive technologies. Adhering to this practice aligns with the following standards:

- WCAG 2.1 (AA): 3.1.2 Language of Parts
- WCAG 2.0 (AA): 3.1.2 Language of Parts
- WCAG 2.2 (AA): 3.1.2 Language of Parts
- Trusted Tester: 11.B - The human language for any content segment that differs from the default human language of the page can be programmatically determined.
- EN 301 549: 9.3.1.2 Language of Parts

## 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. An invalid or missing `lang` attribute can lead to mispronunciations, confusing users and diminishing their experience. This practice aligns with WCAG Success Criterion 3.1.2: Language of Parts.

## How to Fix

To ensure proper language declaration:

- **Specify the Primary Language in the `<html>` Element:** Add a valid two-letter language code to the `lang` attribute in the opening `<html>` tag. 

    <html lang="en">
      <!-- Document content -->
    </html>

- **Include Regional Variants if Necessary:** For dialects or regional language variations, use extended language codes like "en-US" for American English or "fr-CA" for Canadian French. 

    <html lang="en-US">
      <!-- Document content -->
    </html>

- **Indicate Language Changes Within the Document:** When a section of the content is in a different language, use the `lang` attribute on the specific element. 

    <p>This is an English paragraph.</p>
    <p lang="es">Este es un párrafo en español.</p>

- **Specify Text Direction for Right-to-Left Languages:** Use the `dir` attribute to define text direction for languages like Arabic or Hebrew. 

    <p lang="ar" dir="rtl">نص باللغة العربية.</p>

### Examples

#### Incorrect

An HTML document without a `lang` attribute:

    <html>
      <!-- Document content -->
    </html>

#### Correct

An HTML document with a valid `lang` attribute:

    <html lang="en">
      <!-- Document content -->
    </html>

## More Information

- [W3C: Declaring Language in HTML](https://www.w3.org/International/questions/qa-html-language-declarations)
- [IANA Language Subtag Registry](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry)

## Other Rules

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

- [video-caption](https://testingbot.com/support/accessibility/web/rules/video-caption)
- [autocomplete-valid](https://testingbot.com/support/accessibility/web/rules/autocomplete-valid)
- [avoid-inline-spacing](https://testingbot.com/support/accessibility/web/rules/avoid-inline-spacing)
- [target-size](https://testingbot.com/support/accessibility/web/rules/target-size)
- [accesskeys](https://testingbot.com/support/accessibility/web/rules/accesskeys)
