Accessibility Insights

Back to Info and Examples for Accessibility Insights for Web

valid-lang

The lang attribute must have a valid value.

Why it matters

Sometimes a web page written in one language has a passage in a different language. When the language of such a passage is correctly identified (by a lang attribute on the containing element), browsers and assistive technologies can render the text more accurately; screen readers can use the correct pronunciation; visual browsers can display the correct characters; and media players can show captions correctly. All users find it easier to understand the content.

How to fix

Provide a valid lang attribute value:

  1. Identify the passage’s language.
  2. Choose the corresponding language code from the IANA Language Subtag Registry
  3. Make sure the value is spelled correctly.

Example

 

Fail

The default language of the page is English. A passage in Spanish has an invalid language attribute, so assistive technologies ignore it. Screen readers announce the Spanish passage as if it were written in English, making it more difficult to understand.

<html lang="en-US>

<body>

<span id="original">The quick brown fox jumps over the lazy dog.</span>

<span id="translation" lang="sp"> El rápido zorro marrón salta sobre el perro perezoso.</span>
 

Pass

The passage has the correct language attribute for Spanish. Screen readers announce the passage using correct pronunciation, making it easier to understand.

<html lang="en-US>

<body>

<span id="original">The quick brown fox jumps over the lazy dog.</span>

<span id="translation" lang="es"> El rápido zorro marrón salta sobre el perro perezoso.</span>

About this rule

This rule passes if:

  • The lang attribute has a valid value

More examples