HTML lang Global Attribute
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 an ISO language code as its value. 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. - Search engines: Search engines use the
langattribute to improve their search results. For example, if you search for a keyword in English, a search engine will be more likely to return results that are in English. - Content negotiation: Servers can use the
langattribute to negotiate the language of the content that is sent to the client. This is useful for websites that support multiple languages.
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_codeSpecifies the language code for the content of the element.
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.
This global attribute is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 14th October 2023
