HTML lang Attribute

The HTML lang attribute identifies the language of an element's content, helping browsers, screen readers, search engines, and other software interpret the text correctly.

Global Attribute

The lang attribute is a global attribute and can be specified on all HTML elements. It defines the language of an element and is inherited by descendant elements unless they specify their own language.

lang Values

The value of the lang attribute is a single BCP 47 language tag. A language tag can identify a language and, when needed, provide additional information such as a region or writing system.

Value Description
en English.
en-US English as used in the United States.
en-GB English as used in the United Kingdom.
es Spanish.
fr French.
de German.

Use a language tag that accurately describes the content. A regional subtag such as US or GB is useful when the regional distinction is relevant.

Document Language

The primary language of an HTML document should normally be declared with the lang attribute on the <html> element.

<!doctype html>
<html lang="en">
  ...
</html>

Placing lang on the <html> element establishes the language for the document, including content in the <head> and descendant elements that do not specify a different language.

Language Changes

When part of a page uses a different language from the surrounding content, add a lang attribute to the element containing that content.

<p>The French phrase <span lang="fr">bonjour tout le monde</span> means "hello everyone."</p>

This identifies the French phrase without changing the language of the surrounding English content.

Language Inheritance

An element without its own lang attribute normally inherits its language from its parent. This inheritance continues through the document hierarchy until another language is specified.

<section lang="es">
  <h3>Bienvenido</h3>
  <p>Este contenido está escrito en español.</p>
</section>

Both the heading and paragraph are identified as Spanish because they inherit lang="es" from the <section> element.

Accessibility

Correctly identifying the language of a page is important for accessibility. Screen readers can use the language information to select appropriate pronunciation rules and voices.

The primary language should be identified on the <html> element, and significant passages written in another language should identify that language with their own lang attribute.

Common Mistakes

Do not omit the lang attribute from the <html> element simply because the language appears obvious to a reader. Software and assistive technologies need the language to be identified programmatically.

Do not use a country code by itself when you intend to identify a language. For example, use en-US for U.S. English rather than US.

Do not change the document's primary lang value for a short passage in another language. Apply a separate lang attribute to the element containing that passage.

An empty value such as lang="" explicitly indicates that the language is unknown, so use an appropriate language tag when the language is known.

Browser Support

Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.

The lang global attribute is widely supported in current core browsers.

Checking Browser Support

For current browser compatibility information, visit Can I Use? . Search for the HTML element or attribute you want to check. You can also narrow your search by entering an element name and attribute name separated by a colon. Search results can include related HTML features, element attributes, input types, APIs, and other technologies, so select the result that most closely matches the feature you are checking.

Try the lang Attribute

The example uses lang to identify passages written in English, French, Spanish, and German. Each language can be identified independently within the same document.

Play in Editor

Summary

The HTML lang attribute identifies the language of an element using a BCP 47 language tag. It is commonly placed on the <html> element to establish the document's primary language and can also be used on individual elements when the language changes. Correct language information helps browsers, assistive technologies, and other software interpret content properly.