This document is in beta. Help us by reporting issues via Github or email
On this page:
In code, identify the language that the content of the page is written in (English for example).
This makes sure that screen readers automatically use the correct speech libraries for accent and pronunciation.
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.
In HTML, correctly setting the lang
attribute also has other benefits:
<q>
elements are different for different languages;spellcheck
attribute needs it to function properly, especially for multilingual users, as browser heuristics aren’t perfect;3.1.1 Language of Page: The default human language of each Web page can be programmatically determined. (Level A)
This applies to native apps by replacing “Web page” with “app”.
See the W3C’s detailed explanation of this guideline with techniques and examples.
This section needs more content. Contribute via Github or email.
This section needs more content. Contribute via Github or email.
This section needs more content. Contribute via Github or email.
lang
attribute of the html
element.
<html>
element of every page with English content includes lang="en"
.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"
):
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">
<!-- -->
</html>
<html>
<!-- -->
</html>
lang
attribute is present on the html
element.lang
attribute is present on the html
element, but it incorrectly identifies the language of the page.This document is in beta. Help us by reporting issues via Github or email