Microdata is a way to add semantic meaning to HTML elements, making it easier for search engines and other applications to understand the data on your web page. It provides a way to annotate content with machine-readable tags, helping search engines like Google display richer results (e.g., rich snippets) for users.
Microdata is a specification that allows you to embed machine-readable data within HTML documents. It provides a set of attributes that can be added to HTML elements to give meaning to the data, such as identifying a product, a review, or an event. This data can then be used by search engines, browsers, and other applications to improve the visibility and usability of the content.
The basic syntax of Microdata involves three key attributes:
In the following example, we use Microdata to describe a product:
<div itemscope itemtype="http://schema.org/Product"> <h2 itemprop="name">Laptop</h2> <p itemprop="description">A high-performance laptop for everyday use.</p> <span itemprop="price">$999</span> <span itemprop="brand">Dell</span> </div>
In this example:
itemscope
is used to declare the entire div
element as an item.itemtype
specifies the type of the item (in this case, a Product
from schema.org).itemprop
is used to define the properties of the product, such as the name, description, price, and brand.Microdata is most commonly used to annotate the following types of content:
Here's an example of how to describe a review using Microdata:
<div itemscope itemtype="http://schema.org/Review"> <h3 itemprop="name">Great Laptop!</h3> <p itemprop="reviewBody">This laptop is amazing for everyday use. It’s fast, lightweight, and has a long battery life.</p> <span itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating"> <meta itemprop="worstRating" content="1"> <meta itemprop="bestRating" content="5"> <span itemprop="ratingValue">5</span> </span> <p itemprop="author">John Doe</p> </div>
In this example, we define a review using the Review
type from schema.org:
itemscope
and itemtype
declare the item as a review.itemprop="reviewBody"
specifies the text of the review.itemprop="reviewRating"
is used to define the rating given to the item, including its worst and best possible ratings, and the actual rating value.itemprop="author"
provides the name of the person who wrote the review.
Microdata is a powerful tool for adding semantic meaning to your HTML content. By using attributes like itemscope
, itemtype
, and itemprop
, you can help search engines and other applications understand the data on your web pages. This can lead to better visibility in search results and richer user experiences. Whether you're marking up products, reviews, events, or other types of content, Microdata offers a simple yet effective way to enhance the value of your website.