HTML lang Global Attribute
The lang attribute sets the language of an element's content, such as en or fr-CA. Screen readers, translation tools, hyphenation and fonts all use it.
Description
The lang global attribute in HTML specifies the language of the element's content. It is a global attribute, meaning that it can be used on any HTML element. The lang attribute takes a BCP 47 language tag as its value, made of a language code that can be followed by a region or script, such as en-GB or zh-Hant. Common examples are en for English, es for Spanish, and fr for French.
The lang attribute is used for a variety of purposes, including:
- Accessibility: Screen readers and other assistive technologies use the
langattribute to determine the language of the content being read, so that they can pronounce it correctly. - Typography: Browsers use the language to choose fonts and quotation marks, to hyphenate text with
hyphens: auto, and for case conversion withtext-transform. - Styling: The CSS
:lang()pseudo-class selects elements by their language. - Translation: Browser translation tools use it to detect the language of the page.
It is important to note that the lang attribute is different from the xml:lang attribute. The xml:lang attribute is used in XML documents to specify the language of the content. In HTML documents, the lang attribute is preferred.
Here is an example of how to use the lang attribute:
<html lang="en">
<head>
<title>My Website</title>
</head>
<body>
<h1>This is my website.</h1>
</body>
</html>
In this example, the lang attribute is set to en, which means that the language of the content is English.
It is recommended to always specify the lang attribute on your HTML documents. This will help to ensure that your content is displayed and interpreted correctly by users and machines alike.
Syntax
<element lang="language_code">
Values
- language_codeA BCP 47 language tag, such as
en,en-GB,frorzh-Hant. An empty string means the language is unknown.
Example
Browser Support
The following information will show you the current browser support for the HTML lang global attribute. Hover over a browser icon to see the version that first introduced support for this HTML global attribute.
Desktop





Tablets & Mobile





