itemref

The itemref attribute in HTML associates an element with other elements that provide additional details about the item in Microdata, enhancing the context and the information available.

itemref Attribute

In HTML, the itemref attribute is used to link properties from elements that are not directly within an element that has the itemscope attribute. This allows additional details to be associated with an item without needing to nest everything inside a single element.

The itemref attribute refers to other element IDs (not itemid) from elsewhere in the document, providing extra properties for the item.

The itemref attribute is only applicable to elements that have the itemscope attribute.

Syntax

index.js
<element itemref="id1 id2 id3"> ... </element>

Example

Name: Amanda

Band: Jazz Band

Size: 12 players

index.html
<div itemscope id="amanda" itemref="a b"></div>
  <p id="a">Name: <span itemprop="name">Amanda</span></p>
  <div id="b" itemprop="band" itemscope itemref="c"></div>
  <div id="c">
  <p>Band: <span itemprop="name">Jazz Band</span></p>
  <p>Size: <span itemprop="size">12</span> players</p>
</div>

Key Points

  • Purpose: Links properties that are outside the scope of a given itemscope.
  • Usage: To be used on an element with the itemscope attribute to refer to other elements that provide additional properties.
  • Format: The value of itemref consists of the IDs of other elements that contain the supplementary properties.

Benefits

  • Helps maintain semantic connections between elements, even if they are not nested directly within each other.
  • Useful in more complex layouts where properties may need to be separated but still related to a central item.

See Also

Conclusion

The itemref attribute allows elements outside of a given itemscope to contribute additional properties to an item, enhancing the context without requiring direct nesting. It links elements by their IDs, maintaining semantic relationships even in complex layouts. This attribute is essential for structuring detailed data in Microdata, enabling clearer associations between related elements.