What is the lang attribute?
The lang
attribute establishes the primary language of an HTML document. The attribute should be included in the opening <html>
element in a document.
For example, β<html lang="en">
conveys that the primary language of the webpage is English.
The lang
attribute can also be applied to a section of a webpage if you change languages on a page. For example, <p lang="es">Spanish language content would be in this paragraph.</p>
If you use a language that is written from right to left, you should also add the dir
attribute. For example, to show that a span of text is written in Arabic, you would use <span lang="ar" dir="rtl">Arabic text here</span>
.
Why does the lang attribute matter?
The lang
attribute helps browsers, screen readers, and other user agents understand the language context of the document or a specific section, which improves accessibility, localization, and SEO.
Screen readers use the lang
attribute to select the correct pronunciation rules for reading content.
Valid Values
Not only should your page have the lang attribute, but it must also be a valid value. Some of the more common codes are:
en
: Englishfr
: Frenches
: Spanishde
: Germanzh-CN
: Simplified Chinesear
: Arabic
Review Choosing a Language Tag by the W3C for more details on selecting the language tag you need. The full Language Subtag Registry contains all possible language tags.
Getting a valid lang attribute error you just can't figure out?
Be sure to review these Assumptions found within the rules used
β
βhttps://www.w3.org/WAI/standards-guidelines/act/rules/de46e4/
Most notably, this piece here -
This rule assumes that only known primary language tags are enough to satisfy Success Criterion 3.1.2 Language of Parts; this notably excludes grandfathered tags and ISO 639.2 three-letters codes, both having poor support in assistive technologies.
β
Learn More with W3C
Learn More with WCAG
DubBot Flag: html element must have a valid value for the lang
attribute.
If you have questions, please contact our DubBot Support team via email at help@dubbot.com or via the blue chat bubble in the lower right corner of your screen. We are here to help!