On this page:
If the page has content in more than one language (for example, if a page in English has a button labelled in Welsh), identify the language of each part in code.
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.
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.
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
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.
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.
langattribute on the
htmlelement, use the
langattribute again on any part of the document that is written in a different language.
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", the content will be pronounced by screen readers with a British accent, regardless of the users’ preferences. That’s not ideal.
lang="en", the content will be pronounced with the accent that matches the users’ preferences.
<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>
<html> ... <h2>Upcoming Spanish Holidays</h2> <p>Les Fogueres de Sant Joan.</p> ... </html>