HTML itemscope Attribute
The HTML itemscope attribute creates a Microdata item, allowing information within a webpage to be grouped into a set of machine-readable properties.
Global Attribute
The itemscope attribute is a global attribute and is part of HTML Microdata. It can be specified on any HTML element to create a new Microdata item.
Boolean Attribute
The itemscope attribute is a Boolean attribute. Its presence creates a new Microdata item, and it does not require a value.
<div itemscope>
...
</div>
Writing itemscope="false" does not disable the attribute. Because it is a Boolean attribute, its presence means that a Microdata item is created.
How itemscope Works
An element with the itemscope attribute creates a new Microdata item. Descendant elements can use itemprop to provide properties for that item.
<article itemscope>
<h3 itemprop="name">HTML Guide</h3>
<p>Author: <span itemprop="author">Jane Smith</span></p>
</article>
In this example, the <article> creates the item. The name and author properties belong to that item.
An item created with itemscope does not have to specify an itemtype. Without itemtype, the item has no explicitly defined type.
Using itemscope with itemtype
The itemtype attribute can be added to the same element as itemscope to identify the type of item being described.
<article itemscope itemtype="https://schema.org/Book">
<h3 itemprop="name">HTML Guide</h3>
<p>Author: <span itemprop="author">Jane Smith</span></p>
</article>
In this example, itemscope creates the item and itemtype identifies it as a book using the specified vocabulary. The vocabulary determines the meaning of properties such as name and author.
Nested Microdata Items
A Microdata item can contain another Microdata item. When an element has both itemprop and itemscope, the nested item becomes the value of the property identified by itemprop.
<article itemscope itemtype="https://schema.org/Book">
<h3 itemprop="name">HTML Guide</h3>
<div itemprop="author" itemscope itemtype="https://schema.org/Person">
<p>Author: <span itemprop="name">Jane Smith</span></p>
</div>
</article>
Here, the person item is the value of the book's author property. The person's name property belongs to the nested person item rather than directly to the book.
Related Microdata Attributes
The itemscope attribute works with HTML's other Microdata attributes to describe items and their properties.
| Attribute | Description |
|---|---|
itemscope |
Creates a new Microdata item. |
itemtype |
Identifies the vocabulary and type associated with the item. |
itemid |
Provides a global identifier for an item when permitted by its vocabulary. |
itemprop |
Adds one or more properties to an item. |
itemref |
Associates additional properties elsewhere in the document with an item. |
Common Mistakes
Do not add a value to itemscope to identify the type of item. The itemscope attribute is Boolean; use itemtype to specify an item's type.
<!-- Correct -->
<article itemscope itemtype="https://schema.org/Book">
Do not write itemscope="false" when you do not want to create an item. The attribute remains enabled whenever it is present.
Do not use itemtype, itemid, or itemref without satisfying their requirements for itemscope. Both itemtype and itemref require itemscope, while itemid requires both itemscope and itemtype.
Browser Support
Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.
The itemscope attribute used with HTML microdata is supported in current core browsers. Browser support for microdata attributes is generally separate from whether search engines or other consumers use the structured data.
Checking Browser Support
For current browser compatibility information, visit Can I Use? . Search for the HTML element or attribute you want to check. You can also narrow your search by entering an element name and attribute name separated by a colon. Search results can include related HTML features, element attributes, input types, APIs, and other technologies, so select the result that most closely matches the feature you are checking.
Try the itemscope Attribute
The example uses itemscope to create a book item. The itemtype attribute identifies the type of item, while itemprop identifies individual properties belonging to the book.
Summary
The HTML itemscope attribute is a Boolean attribute that creates a new Microdata item. Properties can be added with itemprop, an item type can be identified with itemtype, and other Microdata attributes can provide an identifier or associate additional properties with the item. Microdata items can also be nested to represent relationships between structured pieces of information.
