WCAG 3.1.1: Language of Page
Understanding WCAG 3.1.1 Language of Page
WCAG (Web Content Accessibility Guidelines) Success Criterion 3.1.1, titled “Language of Page”, is a foundational requirement at Level A. Its core principle dictates that the default human language of each web page must be programmatically determinable. This means that assistive technologies, such as screen readers, and other user agents, like search engines and translation tools, can automatically identify the primary language in which the page’s content is written.
This criterion is crucial for providing an inclusive web experience, ensuring that content is correctly interpreted, rendered, and presented to users, regardless of their language or assistive technology.
Why This Criterion Matters: Accessibility Impact and User Benefits
Properly identifying the language of a web page is essential for a wide range of users and has significant accessibility implications:
- Screen Reader Users: For users who rely on screen readers, knowing the page’s language is paramount. When the language is correctly identified, screen readers can load the appropriate pronunciation dictionary, voice, and accent, enabling accurate and comprehensible speech synthesis. Without this, text might be mispronounced, making it difficult or impossible for the user to understand the content.
- Users of Translation Tools: Automatic translation services (e.g., browser extensions, online translators) depend on the programmatically determined language to function effectively. If the language is unspecified or incorrect, these tools may fail to offer a translation, or produce inaccurate and garbled translations.
- Users with Cognitive or Learning Disabilities: Clear, correctly pronounced, and accurately translated content reduces cognitive load. Mispronounced words or poor translations can create significant barriers to understanding for these users.
- Users Who are Deaf or Hard of Hearing: While not directly auditory, accurate language identification ensures that any speech-to-text or captioning services processing page content (e.g., for embedded media transcripts) operate correctly, maintaining the integrity of the information.
- Search Engines: Proper language declaration helps search engines index content more accurately, improving discoverability for users searching in specific languages.
By meeting WCAG 3.1.1, you ensure that your web content is accessible, understandable, and usable by a much broader audience, enhancing the overall user experience.
Success Criterion 3.1.1 Language of Page: Requirements
The official wording for Success Criterion 3.1.1 is straightforward:
3.1.1 Language of Page (Level A): The default human language of each Web page can be programmatically determined.
To satisfy this criterion:
- The primary human language used for the majority of the content on a web page must be explicitly identified.
- This identification must be performed in a machine-readable format that can be interpreted by user agents and assistive technologies.
- This criterion focuses on the default language of the entire page. If specific sections or phrases within the page are in a different language from the primary one, WCAG 3.1.2 “Language of Parts” would also apply, but 3.1.1 specifically addresses the page’s main language.
Practical Guidelines for Compliance
The most widely accepted and effective method for satisfying WCAG 3.1.1 is by using the HTML lang
attribute on the <html>
element.
Using the lang
Attribute
The lang
attribute specifies the primary language of the document. Its value must be a valid language tag as defined by BCP 47 (Tags for Identifying Languages). This typically involves using ISO 639-1 two-letter language codes, optionally followed by ISO 3166-1 alpha-2 country codes for regional variants.
- Basic Language Identification: Use a two-letter primary language subtag (e.g.,
en
for English,es
for Spanish,fr
for French,de
for German,zh
for Chinese). - Regional Language Identification: For more precise language variants, you can include a region subtag (e.g.,
en-US
for American English,en-GB
for British English,fr-CA
for Canadian French,zh-Hans
for Simplified Chinese). While using regional variants is not strictly required for 3.1.1, it can enhance accuracy for specialized screen reader voices and translation tools.
Placement of the lang
Attribute
The lang
attribute should always be placed on the <html>
element. This is because the <html>
element is the root element of the document, and an attribute placed here is inherited by all descendant elements unless explicitly overridden. This ensures that the declared language applies to the entire document by default.
Examples of Implementation
Correct Implementations
Example 1: English Language Page
The entire page content is in English, and the lang
attribute reflects this.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to Our Site</title>
</head>
<body>
<header>
<h1>Our Company Name</h1>
</header>
<main>
<p>This content is written primarily in English for a global audience.</p>
</main>
<footer>
<p>© 2023 All Rights Reserved.</p>
</footer>
</body>
</html>
Example 2: Spanish Language Page
The entire page content is in Spanish, correctly identified by the lang
attribute.
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bienvenido a Nuestro Sitio</title>
</head>
<body>
<header>
<h1>Nombre de Nuestra Empresa</h1>
</header>
<main>
<p>Este contenido está escrito principalmente en español para una audiencia global.</p>
</main>
<footer>
<p>© 2023 Todos los derechos reservados.</p>
</footer>
</body>
</html>
Example 3: French (Canadian) Language Page with Regional Variant
Using a regional variant for specific language targeting (e.g., Canadian French).
<!DOCTYPE html>
<html lang="fr-CA">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bienvenue sur Notre Site (Canada)</title>
</head>
<body>
<header>
<h1>Nom de Notre Entreprise</h1>
</header>
<main>
<p>Ce contenu est principalement rédigé en français canadien pour un public local.</p>
</main>
<footer>
<p>© 2023 Tous droits réservés.</p>
</footer>
</body>
</html>
Incorrect Implementations
Example 1: Missing lang
Attribute
The most common failure. The language is not programmatically determined, thus failing WCAG 3.1.1.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Untitled Page</title>
</head>
<body>
<h1>Hello World</h1>
<p>This page lacks a specified language, making it inaccessible to some tools.</p>
</body>
</html>
Example 2: Invalid lang
Attribute Value
Using a non-standard or incorrect language code will not be understood by assistive technologies or translation tools.
<!DOCTYPE html>
<html lang="english"> <!-- 'english' is not a valid BCP 47 language tag; should be 'en' -->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My English Page</title>
</head>
<body>
<h1>Welcome to Our Website</h1>
<p>The language code used here is not standard and will be ignored by many tools.</p>
</body>
</html>
Example 3: Mismatched lang
Attribute and Content
The lang
attribute declares one language, but the primary content of the page is in another. This will cause screen readers to mispronounce the content significantly.
<!DOCTYPE html>
<html lang="fr"> <!-- Declares French, but content is primarily English -->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My English Page</title>
</head>
<body>
<h1>Welcome to Our Website</h1>
<p>This content is written in English, but the page language is incorrectly set to French.</p>
</body>
</html>
Best Practices and Common Pitfalls
Best Practices
- Always Include
lang
: Make the inclusion of thelang
attribute on the<html>
element a standard practice for every web page you create. - Use Valid Language Codes: Always refer to BCP 47 (Tags for Identifying Languages) for standard language codes. ISO 639-1 two-letter codes are generally sufficient for the primary language.
- Match Content Language: Critically, ensure that the declared language in the
lang
attribute accurately reflects the actual primary human language of the page’s content. - Consistency in Multilingual Sites: For websites that offer content in multiple languages, ensure that each translated version of a page correctly declares its respective language via the
lang
attribute on its<html>
element. - Dynamic Content / SPAs: For Single Page Applications (SPAs) or content loaded dynamically that fundamentally changes the primary language of the page, ensure that the
lang
attribute on the<html>
element is updated programmatically to reflect the new primary language.
Common Pitfalls
- Forgetting the
lang
Attribute: This is the most frequent oversight and directly leads to a WCAG 3.1.1 failure. Many developers simply overlook this small but important detail. - Incorrect or Non-Standard Language Codes: Using informal language names (e.g.,
lang="french"
instead oflang="fr"
orlang="deu"
instead oflang="de"
) will prevent assistive technologies from recognizing the language. - Default Template Language Mismatch: In development workflows using templating systems or content management systems (CMS), the default template might set
lang="en"
. If content in another language (e.g., Spanish) is then populated into this template, thelang
attribute may not be updated, leading to a mismatch. Always verify the final rendered HTML. - Confusing
lang
with CSS::lang()
orxml:lang
: While CSS’s::lang()
pseudo-class can be used for styling based on language, andxml:lang
is relevant for XML documents (or XHTML), neither serves the purpose of programmatically determining the page language for accessibility as effectively and universally as the HTMLlang
attribute. The HTMLlang
attribute is the authoritative source for this criterion.
Conclusion
WCAG 3.1.1 “Language of Page” might seem like a small detail, but its impact on accessibility is profound. By correctly implementing the lang
attribute on your <html>
element with an accurate BCP 47 language tag, you significantly enhance the accessibility and usability of your web content. This simple yet critical step ensures that assistive technologies can function as intended, translation tools provide accurate results, and a diverse range of users can access and understand your information without unnecessary barriers, contributing to a more inclusive web for all.