lang
Lang Attribute
The lang
attribute in HTML defines the language of the content within an element, helping with accessibility and search engine optimization. It is commonly applied to the <html>
tag but can be used on any HTML element.
- Purpose: This attribute allows screen readers and search engines to correctly identify the language of the content, improving accessibility, translation, and content indexing.
- Usage: While it's most often set on the
<html>
element, you can also apply it to any HTML element to define a different language for specific sections.
Syntax
<tag lang="language_code">Content</tag>
Example
Here’s an example demonstrating the use of the lang
attribute:
This is a paragraph.
Ceci est un paragraphe.
<p>This is a paragraph.</p>
<p lang="fr">Ceci est un paragraphe.</p>
Key Points
- Inheritance: When set on the
<html>
element, thelang
attribute is inherited by all child elements, unless it is explicitly overridden. - Accessibility: The
lang
attribute assists screen readers by enabling them to pronounce the text accurately based on its language. - Search Engines: It helps search engines identify the language of the content, enhancing regional indexing and content relevancy.
See Also
- All global attributes
- HTML
translate
attribute
Conclusion
The lang
attribute in HTML defines the language of an element's content, helping browsers and search engines process and display text appropriately. It enhances accessibility by aiding screen readers and improves SEO by providing accurate linguistic context. The attribute can be applied to any HTML element, with inheritance from the <html>
element for consistent language identification.
itemtype
The itemtype attribute in HTML defines the type of an item within a structured data framework (Microdata), specifying its schema or class to enhance its semantic meaning for search engines.
name
The name attribute in HTML is used to assign an identifier to form elements, ensuring that their data is included in the form submission sent to the server.