This document is in beta. Help us by reporting issues via Github or email.
On this page:
This makes sure that screen readers automatically use the correct speech libraries for accent and pronunciation.
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)
See the W3C’s detailed explanation of this guideline with techniques and examples.
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.