What is the lang attribute?
The lang
attribute conveys the primary language of an HTML document. The attribute should be appended to the opening <html>
element in a document.
Sample:
<html lang="en">
relays that the primary language of the document 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 content 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, <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, improving 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.
Learn More with W3C
Learn More with WCAG
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!