The HTML lang attribute
The HTML lang attribute declares the language of an element's text using a BCP 47 language tag, e.g. lang="en" or lang="pt-BR". Set it on <html> for the whole page and on any element whose language differs. It is a global attribute that helps screen readers, translation tools and search engines.
Overview
The lang attribute tells browsers and tools what language an element's content is written in, using a standard BCP 47 tag such as en, en-GB, fr or ar.
Set it once on the <html> element to declare the page's primary language, then add it to any passage written in another language. Screen readers use it to switch to the correct pronunciation and voice, browser and machine translation use it to translate accurately, search engines use it as a language signal, and CSS can target it with the :lang() selector. It pairs naturally with the dir attribute for right-to-left languages.
Syntax
<html lang="en">
…
<p>She whispered <span lang="fr">au revoir</span> and left.</p>
</html>
Values
| Value |
|---|
| A BCP 47 language tag, e.g. en, en-US, fr, pt-BR, ar, zh-Hans. |
Example
<p>The French word <span lang="fr">château</span> means castle.</p>
Best practices
- Always set
langon the<html>element — it is one of the cheapest accessibility wins available. - Mark up individual phrases in other languages with their own
langso they are pronounced correctly. - Use valid BCP 47 codes and add a region when it matters (
en-GBvsen-US). - Keep
langin sync with the actual content language, including on dynamically swapped content.
Accessibility
The lang attribute is critical for screen-reader users: it tells the screen reader which language rules and voice to use, so a French phrase is read with French pronunciation instead of being mangled by an English voice. A page with no lang on <html> is a common, easily-fixed accessibility failure.
Frequently asked questions
What is the HTML lang attribute for?
Where should I set the lang attribute?
<html> element for the whole document, and on any element containing text in a different language.What values does lang accept?
en, en-US, pt-BR, zh-Hant.