lang
The language of the element’s content, for example pl or en.
- Applies to
- All HTML elements
Example
#<p lang="en">Quote of the day: <q>Less is more.</q></p>
<p lang="pl">Cytat dnia: <q>Mniej znaczy więcej.</q></p>
<p lang="de">Zitat des Tages: <q>Weniger ist mehr.</q></p>Definition and usage
#The lang attribute says what language the content of the element and its descendants is in. The most important place is the <html lang="en"> tag, which sets the language of the whole page.
Many things depend on this information: pronunciation in screen readers, hyphenation in CSS (hyphens: auto), automatic translation, and even the shape of the quotation marks generated by <q>.
Mark passages in another language separately, for example a quote in Polish inside English text. The value is a language code following the BCP 47 standard: pl, en, en-GB, pt-BR.
Syntax
#<element lang="language-code">…</element>Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Always set
langon the<html>element. A missing attribute is one of the most common accessibility errors. - A language code is not a country code: for English you write
en, notukorgb.
Related entries
#- dirText direction: left to right, right to left, or automatic.
- <html>The root of an HTML document. Every other element on the page lives inside it.
- <q>A short quote woven into a sentence. The browser adds the quotation marks itself.
- translateLets you turn off automatic translation of a part of the page, for example a brand name or code.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.