Microdata in HTML5 is a specification that allows web developers to embed machine-readable data into HTML documents. It provides a way to add specific semantic annotations to HTML content, making it easier for search engines and other applications to understand the information on a web page.
The primary purpose of microdata is to structure data in a way that search engines can better interpret and present in search results. It uses a set of attributes and properties to define the meaning and relationships between different pieces of information on a web page.
Here's a basic example of how microdata is used in HTML:
<!DOCTYPE html>
<html>
<head>
<title>Microdata Example</title>
</head>
<body>
<div itemscope itemtype="http://schema.org/Person">
<h1 itemprop="name">John Doe</h1>
<p>
Occupation: <span itemprop="jobTitle">Software Developer</span><br>
Age: <span itemprop="age">30</span>
</p>
</div>
</body>
</html>
In this example:
-
The
itemscope
attribute is used to define the scope of the microdata. It indicates that the data within thediv
element is about a particular item. -
The
itemtype
attribute specifies the type of item being described. Here, it's a Person according to the schema.org vocabulary. -
itemprop
attributes are used to define properties of the item. For instance, "name," "jobTitle," and "age" are properties of the Person item, and their values are specified within the corresponding HTML elements.
Search engines can parse this microdata to understand that the content within the div represents information about a person, their name, job title, and age. This structured data can then be used to enhance search results with rich snippets or other forms of improved presentation.
Microdata, along with other structured data formats like RDFa and JSON-LD, helps make web content more understandable to machines, aiding in better search engine indexing and potential display enhancements in search results.