Microdata is a way to label the content on a web page so that machines can read it, without writing that content twice. You add a few attributes to the HTML you already have, and the text a visitor reads becomes data too: this span is a product name, that one is its price.
It's part of the HTML standard, which describes microdata as groups of name-value pairs added alongside a page's existing content. WHATWG HTML Each group is an item, and each name-value pair is a property.
On most websites, microdata carries the schema.org vocabulary, which search engines read as structured data.
The five attributes
| Attribute | What it does |
|---|---|
itemscope |
Starts an item: everything inside this element can belong to it. See itemscope |
itemtype |
Says what kind of item it is, as a URL from a vocabulary, such as https://schema.org/Product |
itemprop |
Names a property; the element's content is the value. See itemprop |
itemid |
Gives the item a global identifier, such as a book's ISBN |
itemref |
Adds properties from elsewhere on the page, by their id |
An example
Here's a product page marked up with microdata and schema.org:
<div itemscope itemtype="https://schema.org/Product">
<h1 itemprop="name">Trail Runner 2</h1>
<img itemprop="image" src="/images/trail-runner-2.jpg" alt="Trail Runner 2 shoe in blue">
<p itemprop="description">Waterproof trail running shoe with deep grip for mud and wet rock.</p>
<div itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating">
Rated <span itemprop="ratingValue">4.6</span> out of 5
from <span itemprop="reviewCount">128</span> reviews
</div>
<div itemprop="offers" itemscope itemtype="https://schema.org/Offer">
<meta itemprop="priceCurrency" content="USD">
$<span itemprop="price">89.00</span>
<link itemprop="availability" href="https://schema.org/InStock">In stock
</div>
</div>
A few things to notice:
- Items nest. The rating and the offer are items of their own, each attached to the product through an
itemprop. - Most values are the visible text. "Trail Runner 2" is the name because it's the text inside the element.
- Some elements give their value differently. An
imgoragives itssrcorhref, atimeelement itsdatetime, and ametaelement itscontent. That's how the currency codeUSDis supplied next to the visible "$" sign.
Microdata, JSON-LD or RDFa?
Google reads all three formats and says they're equally fine when the markup is valid. It recommends JSON-LD where your setup allows, because it's the easiest to implement and maintain at scale. JSON-LD sits in a separate <script> block, while microdata and RDFa are woven into the visible HTML.
| Your situation | A good choice |
|---|---|
| You can add a script block to your templates | JSON-LD |
| Your theme or CMS already outputs microdata, and it validates | Keep the microdata |
| You want the data to change whenever the visible text changes, from the same template | Microdata |
| You're starting fresh with nested or complex data | JSON-LD |
If a page ends up with two formats, for example microdata from the theme and JSON-LD from a plugin, make sure they describe the same facts with the same values.
Rules that apply to any format
- Mark up only what visitors can see. Google says not to mark up content that's hidden from readers, and Bing says markup must reflect visible content. Microdata makes this easy, since it sits on the visible text.
- Valid isn't the same as shown. Correct markup makes a page eligible for rich results, but Google doesn't guarantee them.
- Test before and after you publish. Use Google's Rich Results Test to see which Google features a page qualifies for, and the Schema Markup Validator at validator.schema.org to check schema.org markup in general. After launch, watch the rich result reports in Search Console, because template changes can break markup.
For an older, class-based way of labeling HTML, see microformats.