itemref
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
<element itemref="id1 id2 id3"> ... </element>
Example
Name: Amanda
Band: Jazz Band
Size: 12 players
<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
- Other global attributes
- Additional Microdata-related global attributes:
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.
itemprop
The itemprop attribute in HTML is used to define properties within a structured data format (Microdata), offering more context about an item for search engines and other applications.
itemscope
The itemscope attribute in HTML defines a scope for a collection of Microdata items, indicating that the elements within it represent a specific item and its related properties.