accessibility-guidelines

This document is in beta. Help us by reporting issues via Github or email.

Back to the overview page

Language of parts

Does your page include content in more than one language? (For example, a page in English with a paragraph in Welsh).
→ In code, identify the language of each part of the page.

When content is displayed in a language that is different from the primary language of the page, it must be indicated in a way that assistive technologies understand.


On this page:


Requirements

Content that is written in a different language from the main language of the page, should be identified in code.

For multi-lingual content, the language for anything that varies from the default language of the page or app must be defined in the local code for the correct speech synthesizer to be used. This includes image alternatives, form labels, quotes, objects, media alternatives, and other elements. It will over-ride the specified default language and any language and dialect setting specified on the users device.

Example

The homepage of the website of the Canadian Government is written in English, so it has <html lang="en">. On the homepage, there’s link to access the version written in French. The link text reads “Français”. The link text is written in French, so the language of the link text is identified with <a lang="fr">.

Common mistakes

Why?

This ensures that screen readers switch to the appropriate accent and pronunciation for that language.

When listening, correct pronunciation helps understanding. For users of assistive technologies such as screen readers it is particularly important, as some have different speech synthesizers for different languages. For example, “chat” means something different when using English pronunciation rather than French.

Official wording in the Web Content Accessibility Guidelines

3.1.2 Language of Parts: The human language of each passage or phrase in the content can be programmatically determined except for proper names, technical terms, words of indeterminate language, and words or phrases that have become part of the vernacular of the immediately surrounding text. (Level AA)

See the W3C’s detailed explanation of this guideline with techniques and examples.


Guidance for Design


Guidance for Web

Note: It’s better to only use the two-letter code representing the language (like lang="en"), rather than including the country as well (like lang="en-gb" or lang="en-us"):

Examples

<html lang="en">
  ...
  <body>
    <p>This page is written in English.</p>
    <p lang="fr">Sauf pour ce qui est écrit en français.</p>
  </body>
</html>
<html lang="en">
  ...
  <h2>Upcoming Spanish Holidays</h2>
  <p lang="es">Les Fogueres de Sant Joan.</p>
  ...
</html>

Failure example

<html>
  ...
  <h2>Upcoming Spanish Holidays</h2>
  <p>Les Fogueres de Sant Joan.</p>
  ...
</html>

More guidance for Web


More info

Sources

Contribute

This document is in beta. Help us by reporting issues via Github or email.