HTML reference
itemref
The Microdata itemref attribute lets an item include properties from elements elsewhere in the same document by referring to their IDs.
What you will learn
- How
itemrefpoints to distant elements - How its ID list relates to
itemscope - When simpler, nested HTML is a better choice
Conceptual example
<article itemscope itemtype="https://schema.org/Product" itemref="price">
<h2 itemprop="name">Notebook</h2>
</article>
<p id="price" itemprop="price">12</p>The item points to the element whose id is price. Its itemprop then contributes a property to the item, even though it is not a descendant in the HTML tree.
Use with care
- IDs must be unique and must point to the intended elements.
- Keep the visible structure understandable to readers and maintainers.
- Prefer nesting properties inside the item when that is clear and valid.
- Validate the final Microdata; a browser will not warn you about every semantic mistake.