What Is Microdata? β Definition and How It Works
Learn how HTML microdata marks up structured data with itemscope and itemprop, and how it compares with JSON-LD and RDFa.
Microdata is an HTML syntax for embedding structured data in a page using attributes on the elements that already display the content, rather than in a separate block.
1. The Attributes
| Attribute | Purpose |
|---|---|
itemscope |
Declares that this element describes an item |
itemtype |
The item's type, as a vocabulary URL |
itemprop |
Names a property of the enclosing item |
itemid |
A global identifier for the item |
itemref |
Pulls in properties from elsewhere in the document |
2. An Example
<div itemscope itemtype="https://schema.org/Product">
<h1 itemprop="name">Wireless Keyboard</h1>
<img itemprop="image" src="/kb.jpg" alt="">
<p itemprop="description">Compact mechanical keyboard.</p>
<div itemprop="offers" itemscope itemtype="https://schema.org/Offer">
<span itemprop="price" content="79.99">$79.99</span>
<meta itemprop="priceCurrency" content="USD">
<link itemprop="availability" href="https://schema.org/InStock">
</div>
</div>
Two details carry most of the practical weight: nesting an itemscope inside an itemprop creates a nested item, and content, meta, and link supply machine-readable values where the visible text is formatted for humans.
3. Where Values Come From
The value of an itemprop depends on the element:
metaβ thecontentattributea,link,areaβhrefimg,audio,video,iframeβsrctimeβdatetimedataβvalue- anything else β the element's text content
A parser that only reads text content gets URLs wrong, and gets dates in whatever display format the page uses rather than the ISO value in datetime.
4. Extraction
import extruct, requests
html = requests.get(url, timeout=30).text
data = extruct.extract(html, syntaxes=["microdata", "json-ld", "rdfa"], uniform=True)
for item in data["microdata"]:
print(item.get("type"), item.get("properties", {}).get("name"))
Extract all three syntaxes rather than choosing one. Pages frequently carry more than one, and they do not always agree β a disagreement is itself worth logging, because it usually means one of them is stale.
5. Microdata Versus JSON-LD and RDFa
| Microdata | JSON-LD | RDFa | |
|---|---|---|---|
| Location | Attributes on visible markup | A <script> block |
Attributes on visible markup |
| Coupling to layout | Tight | None | Tight |
| Search-engine preference | Supported | Recommended | Supported |
| Breaks on redesign | Easily | Rarely | Easily |
| Duplication of values | None | Values repeated | None |
JSON-LD is now the recommended form for most purposes, largely because decoupling the data from the markup means a template change does not silently destroy it.
For extraction, though, microdata's coupling is occasionally an advantage: because the values are the displayed ones, they cannot drift out of sync with what a user sees, which a stale JSON-LD block certainly can.
6. Why It Still Appears
Enormous numbers of pages carry microdata from earlier CMS themes, e-commerce platforms, and plugins. Any extractor working across a broad set of sites will meet it constantly, so support is not optional.
itemref is the piece most implementations get wrong β it references properties defined elsewhere in the document by ID, so an extractor that only walks the subtree misses those values entirely.
7. Summary
Microdata embeds structured data as itemscope, itemtype, and itemprop attributes on the markup that already displays the content, with nesting for sub-items and meta/link elements for machine-readable values.
JSON-LD is now generally preferred because it survives redesigns, but microdata remains widespread β so extract every syntax present, respect the per-element value rules, and handle itemref rather than only walking the subtree.