---
title: HTML lang & xml:lang Match | Accessibility Rule
description: HTML elements with lang and xml:lang must have the same base language
source_url:
  html: https://testingbot.com/support/accessibility/web/rules/html-xml-lang-mismatch
  md: https://testingbot.com/support/accessibility/web/rules/html-xml-lang-mismatch/index.md
---
# Ensure that HTML elements with both valid lang and xml:lang attributes agree on the base language of the page

Rule ID: html-xml-lang-mismatchUser Impact: moderateGuidelines: WCAG 2.0

To maintain accessibility, the `<html>` element should have matching `lang` and `xml:lang` attributes, both specifying the same primary language of the document.

## About This Rule

This rule ensures that the `<html>` element has consistent `lang` and `xml:lang` attributes, both containing valid and identical language codes. Adhering to this practice enhances accessibility for users of assistive technologies by providing clear language declarations.

## Why It Matters

Screen readers and other assistive technologies rely on language attributes to determine the correct pronunciation and interpretation of content. Inconsistent or missing language declarations can lead to misinterpretation, making content difficult to understand for users who depend on these technologies.

## How to Fix

To ensure consistency:

- **Add Matching Language Attributes:** Assign both `lang` and `xml:lang` attributes to the `<html>` element, ensuring they have identical values. For example, for an English document: 

    <html lang="en" xml:lang="en">
      <!-- document head and body -->
    </html>

- **Use Valid Language Codes:** Utilize standard language codes, such as "en" for English, "fr" for French, or more specific codes like "en-US" for American English. A comprehensive list of language codes is available on the [ISO Codes for the Representation of Names of Languages](https://www.loc.gov/standards/iso639-2/php/code_list.php). 
- **Specify Languages for Sections:** For documents containing multiple languages, apply the `lang` attribute to relevant elements: 

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

- **Indicate Text Direction for Right-to-Left Languages:** For languages like Arabic or Hebrew, include the `dir` attribute: 

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

## Other Rules

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

- [image-alt](https://testingbot.com/support/accessibility/web/rules/image-alt)
- [input-button-name](https://testingbot.com/support/accessibility/web/rules/input-button-name)
- [input-image-alt](https://testingbot.com/support/accessibility/web/rules/input-image-alt)
- [label](https://testingbot.com/support/accessibility/web/rules/label)
- [link-in-text-block](https://testingbot.com/support/accessibility/web/rules/link-in-text-block)
