Deutsch

The HTML lang attribute declares the human language of an element’s content. It usually sits on the <html> tag and holds a language tag such as en or pt-BR. Screen readers, browsers and spell checkers use it, and it applies to the element and everything inside it.

How does the lang attribute work?

The value is a language tag following BCP 47, for example fr, en-GB or zh-Hans. An element without its own lang inherits the value of its parent. An empty value (lang="") means the language is unknown.

Screen readers pick the pronunciation from it, and browsers choose hyphenation and spell-check dictionaries. CSS can target elements with the :lang() pseudo-class. Accessibility guidelines (WCAG) require that the language of a page and of passages in other languages can be determined by software.

The W3C recommends always setting lang on the html element. A passage in another language gets its own lang on the element around it. For plain HTML documents, lang alone is enough, and the W3C advises against using <meta http-equiv="Content-Language"> to declare a page’s language.

Does the lang attribute matter for SEO?

Google states that it does not use hreflang or the HTML lang attribute to detect the language of a page. It uses its own algorithms. The attribute therefore matters mainly for accessibility and display. Linking language versions of a page to each other is the job of hreflang.

Example

HTML
<html lang="en">
  <body>
    <p>The book is titled <span lang="fr">Le Bon Usage</span>.</p>
  </body>
</html>

Common mistakes

  • A copied template still carries lang="en" on German content.
  • The lang attribute is missing from the html tag.
  • The value uses an underscore (en_US). BCP 47 joins subtags with a hyphen (en-US).

FAQ

Does lang replace hreflang? No. lang describes the language of one page or element. hreflang connects the language versions of a page.

Can lang be set on a single paragraph? Yes. It is a global attribute and works on any element.

Sources

  1. lang – Global attributes – MDNdeveloper.mozilla.org
  2. Declaring language in HTML – W3C Internationalizationw3.org
  3. Localized versions of your page – Google Search Centraldevelopers.google.com
  4. Understanding SC 3.1.1: Language of Page – W3C WAIw3.org
  5. Understanding SC 3.1.2: Language of Parts – W3C WAIw3.org
  6. Tags for Identifying Languages (BCP 47, RFC 5646) – IETFrfc-editor.org

Last updated: