HTML lang Global Attribute
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.
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
<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.
- language_codeSpecifies the language code for the content of the element.
<p>This paragraph is English, but the language is not specifically defined.</p>
<p lang="en-GB">This paragraph is defined as British English.</p>
<p lang="fr">Ce paragraphe est défini en français.</p>
The following table will show you the current browser support for the HTML
lang Global Attribute.
|Tablets / Mobile|
Last updated by CSSPortal on: 14th October 2023