Content Language in HTML: A Complete Guide

Master the lang attribute for accessible, SEO-friendly multilingual web content with proper BCP 47 language tags and WCAG compliance.

In modern web development, properly declaring the language of your content is foundational to accessibility, SEO, and user experience. The HTML lang attribute, while simple in syntax, carries significant weight across assistive technologies, search algorithms, and browser features. This guide covers everything you need to know about content language implementation.

Understanding the HTML lang Attribute

The lang attribute is a global HTML attribute that helps define the language of an element: the language that non-editable elements are written in, or the language that editable elements should be written in by the user. The attribute contains a single BCP 47 language tag, which is the international standard for identifying languages.

BCP 47 Language Tags

BCP 47 (Best Current Practice 47) provides the structure for language identification on the web. A language tag consists of:

  • Primary language subtag: Required, usually a 2-3 letter code (e.g., "en" for English, "fr" for French)
  • Script subtag: Optional, 4 letters indicating the writing system (e.g., "Hans" for Simplified Chinese, "Hant" for Traditional Chinese)
  • Region subtag: Optional, 2 letters or 3 digits (e.g., "US" for United States, "GB" for Great Britain)

Examples:

  • lang="en" - English (generic)
  • lang="en-US" - English (United States)
  • lang="en-GB" - English (Great Britain)
  • lang="fr-CA" - French (Canada)
  • lang="zh-Hans" - Chinese (Simplified)
  • lang="zh-Hant" - Chinese (Traditional)

The default value of lang is the empty string, which means the language is unknown. Always specify an appropriate value for this attribute.

Page-Level Language Declaration

Declaring the language on the HTML element is the most critical language declaration in your document. This sets the default language for the entire page and is required for WCAG 3.1.1 compliance.

Why It Matters

Accessibility Impact:

  • Screen readers use the language to determine pronunciation
  • A screen reader set to English will pronounce words differently than one set to Spanish
  • Incorrect language settings lead to confusing or unreadable content for assistive technology users

Browser Features:

  • Spell-checking accuracy depends on language declaration
  • Automatic translation services use this information
  • Text-to-speech synthesis produces better results with correct language

Search Engine Optimization:

  • Search engines use language to understand and index content
  • Helps serve content to the right audience in search results
  • Supports international targeting signals

For comprehensive SEO strategies that include proper language declaration, explore our SEO services to ensure your multilingual content reaches the intended audience.

Syntax and Placement

Place the lang attribute directly on the opening <html> element:

<!DOCTYPE html>
<html lang="en-US">
<head>
 <meta charset="UTF-8">
 <title>Page Title</title>
</head>
<body>
 <!-- Page content -->
</body>
</html>

The character set declaration (UTF-8) should also be included as it affects how characters are rendered across languages.

Element-Level Language Changes

When your page contains content in a different language than the page's primary language, you should mark that content with the appropriate lang attribute. This is required for WCAG 3.1.2 (Language of Parts) compliance.

When to Use Element-Level Language

  • Foreign words or phrases in text
  • Quotations in another language
  • Technical terms from other languages
  • User-generated content in different languages
  • Multilingual websites with mixed content sections

Implementation Examples

<p>The word "<span lang="fr">bonjour</span>" means hello in French.</p>

<blockquote lang="es">
 <p>La vida es lo que sucede mientras estás ocupado haciendo otros planes.</p>
</blockquote>

<article lang="de">
 <h1>Willkommen</h1>
 <p>Dieser Artikel ist auf Deutsch geschrieben.</p>
</article>

Inheritance Behavior

If an element has no lang attribute, it inherits the lang value from its parent element, which may inherit from its parent, and so on. This inheritance cascade means you only need to declare language on ancestor elements.

Proper language handling is a fundamental aspect of professional web development that ensures your content is accessible to global audiences.

Accessibility and WCAG Compliance

The Web Content Accessibility Guidelines (WCAG) include specific success criteria for language declaration that help ensure content is accessible to everyone.

WCAG Success Criteria

3.1.1 Language of Page (Level A): The default human language of each web page can be programmatically determined. This is a foundational accessibility requirement that affects how assistive technologies present content to users.

3.1.2 Language of Parts (Level AA): The human language of each passage or phrase in the content can be programmatically determined when it differs from the default language of the page. This ensures that mixed-language content remains accessible.

Impact on Assistive Technologies

Screen Readers:

  • Use language settings to select the appropriate voice profile
  • Apply correct pronunciation rules for each language
  • Adjust syntax and rhythm based on language-specific rules

Text-to-Speech:

  • Produce more natural-sounding output with correct language
  • Apply appropriate accents and intonation patterns
  • Handle language-specific features like nasal vowels or tonal variations

Braille Translation:

  • Insert proper control codes for accented characters
  • Apply appropriate braille contractions for the language
  • Prevent erroneous Grade 2 braille creation

Building accessible websites with proper language declarations is essential for reaching all users. Learn more about creating inclusive digital experiences through our AI-powered accessibility solutions.

Best Practices and Common Patterns

Recommended Patterns

  1. Always declare language on HTML element
<html lang="en-US">
  1. Use shortest appropriate language code
  • Use lang="en" when regional differences don't matter
  • Use lang="en-US" when US spelling/pronunciation is intended
  1. Keep declarations consistent across your site

  2. Test with accessibility tools regularly

  3. Document your language strategy for team reference

Common Mistakes to Avoid

  1. Missing language declaration<html> → ✅ <html lang="en">

  2. Invalid language codeslang="english" → ✅ lang="en"

  3. Inconsistent language tags ❌ Mixing en and en-US randomly

  4. Forgetting element-level changes ❌ Not marking foreign phrases → ✅ Add lang="fr" to foreign text

  5. Using deprecated attributesxml:lang in HTML5 → Use lang instead

Quick Reference: Common Language Codes

LanguageCodeExample
English (US)en-USAmerican English
English (UK)en-GBBritish English
FrenchfrFrench (generic)
French (Canada)fr-CACanadian French
SpanishesSpanish (generic)
Spanish (Mexico)es-MXMexican Spanish
GermandeGerman
Chinese (Simplified)zh-HansSimplified Chinese
Chinese (Traditional)zh-HantTraditional Chinese
JapanesejaJapanese
KoreankoKorean
Portuguese (Brazil)pt-BRBrazilian Portuguese
ArabicarArabic
HindihiHindi

Summary

Proper content language declaration in HTML is essential for creating accessible, well-optimized websites. Key takeaways include:

  1. Always declare language on the <html> element using a valid BCP 47 language tag
  2. Mark language changes within your content using the lang attribute on specific elements
  3. Use shortest appropriate codes (en over en-US when regional differences don't matter)
  4. Validate for WCAG compliance using tools like WAVE and browser developer tools
  5. Test across assistive technologies to ensure proper pronunciation and behavior

By following these practices, you ensure your content is accessible to users worldwide, properly indexed by search engines, and works correctly with assistive technologies.

Sources

  1. MDN Web Docs - HTML lang global attribute
  2. W3C WAI - Technique H57: Using the language attribute on the HTML element
  3. W3C WAI - Understanding Language of Page (SC 3.1.1)
  4. Pope Tech - How to declare your page's language
  5. BCP 47: Tags for Identifying Languages

Ready to Build Accessible, Multi-Language Websites?

Our web development team specializes in creating accessible, internationalized web applications that work for everyone.