Entity Tracking
- Itemscope: A boolean HTML attribute that creates a new microdata item by defining a scope for name-value pairs.
- Itemtype: An attribute that provides a URL to a specific vocabulary, such as Schema.org, to define the context of an item.
- Itemprop: An attribute used to assign specific properties and values to an item defined by itemscope.
- Microdata: A set of HTML5 tags used to embed machine-readable metadata within existing web content.
- Schema.org: A [collection of shared vocabularies used by major search engines] (Schema.org) including Google, Microsoft, Yandex, and Yahoo!
- Itemref: An attribute used to associate properties with an item when those properties are not descendants of the itemscope element.
- Global Identifier: An ID attribute used alongside itemscope to allow an item to relate to other items across the web.
The itemscope attribute is a boolean value placed on HTML elements to create a new "item" of metadata. It tells search engines and bots that all properties contained within that HTML block belong to a single, specific object. By using this attribute, you help machines understand the meaning of your content rather than just how to display it.
What is Itemscope?
In technical terms, itemscope is a global attribute that defines the scope of associated metadata. When you add it to an element, you create a new group of name-value pairs.
Search engines use these pairs to identify specific entities on a page, such as movies, recipes, or people. This attribute is a core component of [microdata introduced with HTML5] (Schema.org) to provide semantic meaning to the plain text on a website.
Why Itemscope matters
- Improved Search Context: It identifies whether a word like "Avatar" refers to a 3D movie or a profile picture, helping search engines provide more relevant results.
- Rich Results: It provides the data necessary for search engines to display enhanced snippets, such as star ratings, calories, or director names.
- Social Media Clarity: Microdata is [compatible with Facebook's Open Graph Protocol] (StackOverflow), allowing you to define titles and thumbnails for social sharing without redundant code.
- Data Interoperability: Using an
idwithitemscopecreates a global identifier, linking your data to other relevant items found across the web.
How Itemscope works
To use itemscope, you typically pair it with itemtype to declare what the item is.
- Identify the container: Find the HTML element (like a
<div>or<span>) that wraps all the information about a specific topic. - Apply the attribute: Add
itemscopeto that element. This "opens" the scope. - Define the type: Add an
itemtypeattribute with a URL from a vocabulary like Schema.org (e.g.,itemtype="https://schema.org/Movie"). - Label properties: Use
itempropon elements inside the container to define specific details like "name" or "director."
If the properties of an item are located elsewhere on the page and cannot be nested inside the itemscope element, you must use an itemref attribute to link them.
Best practices
- Always include a type: While
itemscopecreates an item, it is rarely useful withoutitemtype. Specify the kind of item you are describing so search engines know which vocabulary to use. - Markup visible content only: As a general rule, only mark up the text that is visible to users on the page. Avoid marking up hidden divs or elements.
- Nest items when necessary: If a property of your item is itself another item (like a "Person" being the "director" of a "Movie"), start a new
itemscopeon the property element. - Use standardized formats: Use the [ISO 8601 date/time standard] (Schema.org) for dates and durations (e.g., YYYY-MM-DD) to ensure machines can interpret them correctly.
- Validate your code: Always check your implementation using [Google's Rich Results Testing Tool] (MDN) to identify errors in the microdata structure.
Common mistakes
- Mistake: Marking up hidden text or meta tags exclusively.
- Fix: Ensure the
itempropattributes are attached to text that a human visitor can actually see on the page. - Mistake: Ambiguous dates like "04/01/11."
- Fix: Use the
<time>tag with thedatetimeattribute to provide a machine-readable format. - Mistake: Forgetting the vocabulary URL.
- Fix: Ensure
itemtypealways points to a full URL (e.g., https://schema.org/Recipe). - Mistake: Using
itemscopealone without properties. - Fix: Adding
itemscopeonly defines the box; you must useitempropto put information inside that box.
Examples
Representing a Movie
In this scenario, itemscope defines the boundaries of the movie data, while itemtype tells the bot to look at the Movie vocabulary on Schema.org.
<div itemscope itemtype="https://schema.org/Movie">
<h1 itemprop="name">Avatar</h1>
<span>Director: <span itemprop="director">James Cameron</span></span>
<span itemprop="genre">Science fiction</span>
</div>
Representing a Recipe with Nested Items
This example shows how itemscope can be used multiple times to define items within items (e.g., the Person who authored the Recipe).
<div itemscope itemtype="https://schema.org/Recipe">
<h2 itemprop="name">Grandma's Holiday Apple Pie</h2>
<span itemprop="author" itemscope itemtype="https://schema.org/Person">
<span itemprop="name">Carol Smith</span>
</span>
<span itemprop="nutrition" itemscope itemtype="https://schema.org/NutritionInformation">
Calories: <span itemprop="calories">250 cal</span>
</span>
</div>
Itemscope vs JSON-LD
| Feature | Itemscope (Microdata) | JSON-LD |
|---|---|---|
| Implementation | Embedded directly in HTML tags | Usually a single script block in the <head> |
| Visibility | Tied to visible page elements | Independent of visible elements |
| HTML Compatibility | Requires specific tagging of DOM nodes | Does not require changing existing HTML structure |
| Nesting | Uses nested HTML tags | Uses nested JSON objects |
Rule of thumb: While [most examples on Schema.org] (Schema.org) show Microdata, RDFa, and JSON-LD, Microdata is most useful when you want to link metadata directly to specific visible page elements.
FAQ
Can I use Itemscope on any HTML element?
Yes, itemscope is a global attribute. You can specify it on any HTML element, though it is most commonly used on <div>, <span>, <section>, or <article> tags to group related information.
What happens if I use Itemscope without Itemtype?
If you specify itemscope without an itemtype, you must use itemref to associate it with properties. Generally, using itemscope alone creates an item of an unspecified type, which search engines find much harder to interpret.
Does Itemscope help with SEO?
While it is not a direct ranking factor in the way a backlink might be, it helps search engines understand your content. This leads to richer displays in search results (rich snippets), which can improve click-through rates.
How do I handle properties that aren't visible, like currency?
If information is implied but not visible (like the currency of a price), you can use the <meta> tag with the content attribute inside the itemscope block. This should be done sparingly and only for data that cannot be marked up otherwise.
Is Itemscope the same as Open Graph?
No, but they are compatible. You can list the same metadata for both search engines (using itemprop) and Facebook (using property="og:...") within the same HTML element to save space and reduce code complexity.