---
title: "Document has a valid language code"
date: "2024-08-19T07:43:53+00:00"
summary: "Learn how to declare valid language codes for web pages to improve accessibility and user experience for diverse audiences."
image:
type: "page"
url: "/web-governance/document-has-valid-language-code"
id: "061d8e76-d270-45a8-8017-50c59963b263"
---

Table of contents will be added

**3.1.1 Language of Page**

Introduction
------------

This document provides information about the related accessibility checks:

*   Document has required `lang` attribute(s)
*   Document has a valid language code
*   Reading order direction is marked using the HTML element’s dir attribute if the documents primary language is read right to left

What
----

The human language of the page must be declared in the code of the page.

Why
---

When the human language of your content is correctly declared, it allows software to accurately present your content. 

Who
---

### Affected users

This check affects the following users who have:

*   Sight impairments: And others who access the site contents with a screen reader or other text-to-speech software, for example, the site should correctly use the English pronunciation to read English content rather than trying to speak English for content written in French.
*   Hearing loss: And other users who rely on captions for video and audio.
*   Cognitive limitations: Such as dyslexia and others who might find it difficult to read written material. Other users in this category include persons with any language or learning disability who use text-to-speech software.
*   Translation needs: Translation software provides automated translations of your content.
    
*   No impairments: Search engines can more accurately show your content to the relevant people because it understands the language of your content. Browsers may not render text content accurately if the language of the web page is not declared correctly.
    

### User story

![A young smiling woman with long blonde hair.](https://acquia.widen.net/content/73370142-df0c-4861-9c61-5b466fa4e2e2/web/Mon_AccessibilityHelpCenter-UserStory-YoungBlondWoman.png)

Maria, a Norwegian carpenter with dyslexia:

_"When I go online to read user manuals for some of the machinery I use, they are written in English but my text-to-speech software will read the English text with a Norwegian voice. That makes it very hard for me to understand the instructions."_

How
---

Follow these steps to repair this issue.

1.  Locate the opening HTML tag at the beginning of your webpage.
    
2.  Add the `lang` attribute to the HTML tag, followed by a valid two or three letter language code to the opening `<html>` element.   
    In the following example code, the `lang` value is set to `en` for English:
    
        <html lang="en">
    
    For XHTML, both `lang` and `xml:lang` must be set to the same value.
    
        <html xml:lang="en" lang=”en”>
    
3.  For languages that are written from right to left, the “`dir`” attribute should be added to the HTML element to ensure proper text directionality. This example shows the "`lang`" attribute set to "`ar`" for Arabic and the "`dir`" attribute is set to "`rtl`".
    
        <html lang="ar" dir="rtl">
    

1.  Note
    
    The value should represent the primary language of the page.
    

_Tip:_ Valid language codes are defined in the [ISO 639 specification](https://www.iso.org/iso-639-language-codes.html)

### Who in your team can typically fix this?

In order to repair issues flagged by this check, refer the issue to:

*   Front-end Development. (HTML knowledge is needed.)
    

Additional resources
--------------------

This section gives links to resources that help with the issues discussed in this document.

### WCAG criteria

*   [WCAG success criterion 3.1.1 Language of Page](https://www.w3.org/TR/UNDERSTANDING-WCAG20/meaning-doc-lang-id.html) (W3C website)
    

### Other links

*   [ISO 639 specification](https://www.iso.org/iso-639-language-codes.html) (a list of valid language codes)
    
*   [Internationalization techniques](https://www.w3.org/International/techniques/authoring-html#gslang)
    
    Related articles
    ----------------
    
    *   [Heading code is not used for visual formatting only](/web-governance/are-headings-used-formatting-0 "Are headings used for formatting?")
        
    *   [ID attributes must be unique](/web-governance/id-attributes-must-be-unique "ID attributes must be unique")
        
    *   [Content on Hover or Focus](/web-governance/does-content-appears-hover-or-focus-block-important-information-or-disappear-users-can-interact-it "Does content that appears on hover or focus block important information or disappear before users can interact with it?")