Skip to content

Lang attribute

Also called html lang, language attribute

What is lang attribute?

The lang attribute is an HTML attribute that declares the human language of an element’s content, set on the <html> element to cover the whole page. Its value is a language code such as en, fr or de, optionally followed by a region, as in en-GB or pt-BR.

Robot using an arm to set a language flag onto a webpage, representing the Lang attribute.

You can also set lang on a smaller element when part of a page is in a different language, for example a quotation in French on an English page. The codes follow the BCP 47 standard, the same family of codes used in hreflang.

Why lang attribute matters for SEO

Screen readers use the lang attribute to choose the right pronunciation, so a missing or wrong value makes a page hard to follow for blind and partially sighted visitors. Browsers use it to offer translation, pick hyphenation rules and choose fonts, and accessibility checks such as Lighthouse flag a missing lang.

Google has said it works out a page’s language from its visible content and does not rely on the lang attribute. That does not make the attribute pointless for SEO: other search engines and tools may use it, and it is part of a clean, accessible page. For targeting languages and regions in Google, use hreflang and separate URLs per language, as described in international SEO.

How to set the lang attribute

  1. Add lang to the <html> element of every template, matching the main language of the content.
  2. Add a region subtag only when it is meaningful, such as en-GB versus en-US.
  3. On multilingual sites, make sure each language version sets its own value rather than inheriting the default.
  4. Mark passages in another language with lang on the containing element.

Lang attribute example

HTML
<html lang="en-GB">
  ...
  <blockquote lang="fr">Je pense, donc je suis.</blockquote>
</html>

Lang attribute FAQ

Does Google use the lang attribute?

Google has said it detects a page’s language from the visible content and does not use code-level language information such as the lang attribute. Use hreflang to point Google at language versions.

What is the difference between lang and hreflang?

lang declares the language of the current page’s content. hreflang lists the other language or regional versions of the page so search engines can show the right one.

Related SEO terms

  • Hreflang

    Hreflang is an annotation that tells search engines which language or regional version of a page to show to which searchers.

  • International SEO

    International SEO is optimising a site to rank in several countries or languages, using the right URL structure, hreflang and localised content.

  • Technical SEO

    Technical SEO is making sure search engines can crawl, render and index your site, covering speed, redirects, canonicals, sitemaps and mobile.

  • Lighthouse

    Lighthouse is Google’s open-source tool that tests a page in a lab and scores its performance, accessibility, best practices and SEO.

Back to the SEO glossary

Put the terms to work

Every term here is something OpenSEO measures. It is open source: start online in a minute, or run it on your own server.