Logo

What are you looking for?

Get help straight from our team...

Use standardized language codes

Accessibility Tips

Use standardized language codes

Apply valid BCP 47 language codes in language attributes (lang) to ensure correct pronunciation by screen readers.

Last updated on 11 Nov, 2025

***This document provides helpful tips to improve your site's accessibility. While it doesn’t guarantee 100% compliance, it’s a great starting point to make your website more inclusive and user-friendly.***

Identification

HTML language attributes must contain valid language codes (Rule ID: valid-lang)

 

Applicable Standards

  • WCAG 2.0, 2.1, 2.2 Level AA (3.1.2)

  • Trusted Tester (11.B)

  • EN 301 549

 

Impact

Serious level impact affecting:

  • Blind users

  • Deafblind users

  • Users with cognitive disabilities

 

Proper Implementation

  • Use valid ISO language codes

  • Specify primary language in HTML root element

  • Mark language changes within content

  • Include direction attribute when needed

  • Use appropriate dialect codes when necessary

 

Examples of Correct Usage

  1. Declaring the Primary Language of a Page:
    The lang="en" attribute is correctly applied to the <html> element, specifying that the primary language of the page is English.

Image
  1. Marking Language Changes:
    The lang="fr" attribute is used to mark French text, ensuring proper pronunciation by screen readers.

Image
  1. Using Dialect-Specific Language Codes:
    The lang="en-GB" attribute specifies that the content uses British English, which is distinct from American English (lang="en-US").

Image
  1. Including Text Direction:
    The lang="ar" and dir="rtl" attributes are used for Arabic text, ensuring correct pronunciation and right-to-left text direction.

       

Image

Common Errors to Avoid

  1. Missing lang Attribute:
    The lang attribute is missing in the <html> element, making it difficult for screen readers to correctly interpret the language.

Image
  1. Invalid Language Code:

      The lang="english" attribute is invalid. Language codes must follow the BCP 47 standard, such as lang="en" for English.

Image
  1. Neglecting Language Changes:
    The French phrase is not marked with lang="fr", so screen readers might mispronounce it based on the page's primary language.

Image
  1. Incorrect Dialect Code:
    The lang="en-CA" (Canadian English) attribute is used incorrectly, as the content is written in British English and should use lang="en-GB".

Image
  1.  Missing dir Attribute for Right-to-Left Text:
    While the text is marked as Arabic with lang="ar", the dir="rtl" attribute is missing, so the text may not display correctly.

Image

Rationale

  • Enables correct pronunciation by screen readers

  • Allows proper language switching

  • Essential for multilingual content accessibility

  • Supports proper text-to-speech synthesis

  • Improves user experience for multilingual users

 

Evaluation Method

  1. Inspect HTML Code:

    • Check that the lang attribute is present in the <html> element to specify the primary language of the page.

    • Inspect specific elements for language changes (e.g., <span lang="fr">) when applicable.

  2. Validate Language Codes:

    • Ensure that all language codes follow the BCP 47 standard (e.g., en for English, fr for French, es for Spanish).

    • Verify that dialects are specified correctly, such as:

      • en-US for American English.

      • en-GB for British English.

  3. Test with Screen Readers:

    • Use a screen reader (e.g., NVDA, JAWS, VoiceOver) to listen to content pronunciation.

    • Verify that the screen reader correctly switches languages or dialects where marked.

  4. Check for Proper Text Direction

    • For right-to-left languages (e.g., Arabic, Hebrew), confirm that the dir="rtl" attribute is applied correctly.

Evaluation Checklist

Image
Did you find this article helpful?
Previous

Provide video captions

Next