What it looks like
The language attribute is written as lang on the html element, the element that wraps the whole page.
<html lang="en">
The value is a short language code, such as en for English, es for Spanish or de for German. A region can be added, as in en-US or pt-BR.
If one part of a page is in another language, that part can carry its own lang attribute.
<p lang="fr">Bon appétit</p>
Why it matters
- Screen readers. A screen reader uses the attribute to choose the right pronunciation. Without it, English text may be read aloud with the rules of another language.
- Translation tools. Browsers and translation tools use it to work out which language they are translating from.
- Browsers. It helps with details such as hyphenation and spell checking in forms.
Like alt text, it is mostly there for accessibility. For search it is a minor detail, because Google works out the language of a page from the visible text. It is still one of the small settings every page should have, along with a viewport tag and a title tag.
The lang attribute is not the same as hreflang. The lang attribute describes the page it is on. Hreflang is a separate set of tags that tells search engines about other language versions of the same page at other addresses.
lang="en" on a site written in another language. The attribute must match the language your visitors actually read.How to check yours
- Open the page, right-click and choose View page source.
- Find the
htmlelement in the first lines and read itslangvalue. - If it is missing or wrong, change the site language in your site settings. Most website builders set the attribute from that setting.
- Run the free audit. It reports a page with no language set.