-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
277 lines (252 loc) · 8.09 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
---
title: itemscope
slug: Web/HTML/Global_attributes/itemscope
page-type: html-attribute
spec-urls: https://html.spec.whatwg.org/multipage/microdata.html#attr-itemscope
---
{{HTMLSidebar("Global_attributes")}}
**`itemscope`** is a boolean [global attribute](/en-US/docs/Web/HTML/Global_attributes) that defines the scope of associated metadata. Specifying the **`itemscope`** attribute for an element creates a new item, which results in a number of name-value pairs that are associated with the element.
A related attribute, [`itemtype`](/en-US/docs/Web/HTML/Global_attributes/itemtype), is used to specify the valid URL of a vocabulary (such as [schema.org](https://schema.org/)) that describes the item and its properties context. In each of the following examples, the vocabulary is from [schema.org](https://schema.org/).
Every HTML element may have an `itemscope` attribute specified. An `itemscope` element that does not have an associated `itemtype` must have an associated `itemref`.
> **Note:** Find more about `itemtype` attributes at <https://schema.org/Thing>
### itemscope id attributes
When you specify the `itemscope` attribute for an element, a new item is created. The item consists of a group of name-value pairs. For elements with an `itemscope` attribute and an `itemtype` attribute, you may also specify an [`id`](/en-US/docs/Web/HTML/Global_attributes#id) attribute. You can use the `id` attribute to set a global identifier for the new item. A global identifier allows the item to relate to other items found on pages across the Web.
## Examples
### Representing structured data for a movie
The following example specifies the `itemtype` as "http\://schema.org/Movie", and specifies four related `itemprop` attributes.
<table class="standard-table">
<tbody>
<tr>
<td rowspan="6">itemscope</td>
<td>Itemtype</td>
<td colspan="2">Movie</td>
</tr>
<tr>
<td>itemprop</td>
<td>(itemprop name)</td>
<td>(itemprop value)</td>
</tr>
<tr>
<td>itemprop</td>
<td>director</td>
<td>James Cameron</td>
</tr>
<tr>
<td>itemprop</td>
<td>genre</td>
<td>Science Fiction</td>
</tr>
<tr>
<td>itemprop</td>
<td>name</td>
<td>Avatar</td>
</tr>
<tr>
<td>itemprop</td>
<td>Trailer</td>
<td>https://youtu.be/0AY1XIkX7bY</td>
</tr>
</tbody>
</table>
```html
<div itemscope itemtype="https://schema.org/Movie">
<h1 itemprop="name">Avatar</h1>
<span>
Director: <span itemprop="director">James Cameron</span> (born August 16,
1954)
</span>
<span itemprop="genre">Science fiction</span>
<a href="https://youtu.be/0AY1XIkX7bY" itemprop="trailer">Trailer</a>
</div>
```
### Representing structured data for a recipe
There are four `itemscope` attributes in the following example. Each `itemscope` attribute sets the scope of its corresponding `itemtype` attribute. The `itemtype`s, `Recipe`, `AggregateRating`, and `NutritionInformation` in the following example are part of the [schema.org](www.schema.org) structured data for a recipe, as specified by the first `itemtype`, `http://schema.org/Recipe`.
<table class="standard-table">
<tbody>
<tr>
<td rowspan="14">itemscope</td>
<td>itemtype</td>
<td colspan="2">Recipe</td>
</tr>
<tr>
<td>itemprop</td>
<td>name</td>
<td>Grandma's Holiday Apple Pie</td>
</tr>
<tr>
<td>itemprop</td>
<td>image</td>
<td>https://c1.staticflickr.com/1/30/42759561_8631e2f905_n.jpg</td>
</tr>
<tr>
<td>itemprop</td>
<td>datePublished</td>
<td>2022-11-05</td>
</tr>
<tr>
<td>itemprop</td>
<td>description</td>
<td>
This is my grandmother's apple pie recipe. I like to add a dash of
nutmeg.
</td>
</tr>
<tr>
<td>itemprop</td>
<td>prepTime</td>
<td>PT30M</td>
</tr>
<tr>
<td>itemprop</td>
<td>cookTime</td>
<td>PT1H</td>
</tr>
<tr>
<td>itemprop</td>
<td>totalTime</td>
<td>PT1H30M</td>
</tr>
<tr>
<td>itemprop</td>
<td>recipeYield</td>
<td>1 9" pie (8 servings)</td>
</tr>
<tr>
<td>itemprop</td>
<td>recipeIngredient</td>
<td>Thinly-sliced apples: 6 cups</td>
</tr>
<tr>
<td>itemprop</td>
<td>recipeIngredient</td>
<td>White sugar: 3/4 cup</td>
</tr>
<tr>
<td>itemprop</td>
<td>recipeInstructions</td>
<td>
1. Cut and peel apples 2. Mix sugar and cinnamon. Use additional sugar
for tart apples.
</td>
</tr>
<tr>
<td>itemprop</td>
<td colspan="2">author [Person]</td>
</tr>
<tr>
<td>itemprop</td>
<td>name</td>
<td>Carol Smith</td>
</tr>
<tr>
<td rowspan="3">itemscope</td>
<td>itemprop[itemtype]</td>
<td colspan="2">aggregateRating [AggregateRating]</td>
</tr>
<tr>
<td>itemprop</td>
<td>ratingValue</td>
<td>4.0</td>
</tr>
<tr>
<td>itemprop</td>
<td>reviewCount</td>
<td>35</td>
</tr>
<tr>
<td rowspan="4">itemscope</td>
<td>itemprop[itemtype]</td>
<td colspan="2">nutrition [NutritionInformation]</td>
</tr>
<tr>
<td>itemprop</td>
<td>servingSize</td>
<td>1 medium slice</td>
</tr>
<tr>
<td>itemprop</td>
<td>calories</td>
<td>250 cal</td>
</tr>
<tr>
<td>itemprop</td>
<td>fatContent</td>
<td>12 g</td>
</tr>
</tbody>
</table>
> **Note:** A handy tool for extracting microdata structures from HTML is Google's [Rich Results Testing Tool](https://search.google.com/test/rich-results). Try it on the HTML shown here.
#### HTML
```html
<div itemscope itemtype="https://schema.org/Recipe">
<h2 itemprop="name">Grandma's Holiday Apple Pie</h2>
<img
itemprop="image"
src="https://c1.staticflickr.com/1/30/42759561_8631e2f905_n.jpg"
width="50"
height="50" />
<p>
By
<span itemprop="author" itemscope itemtype="https://schema.org/Person">
<span itemprop="name">Carol Smith</span>
</span>
</p>
<p>
Published:
<time datetime="2022-11-05" itemprop="datePublished">
November 5, 20022
</time>
</p>
<span itemprop="description">
This is my grandmother's apple pie recipe. I like to add a dash of nutmeg.
</span>
<br />
<span
itemprop="aggregateRating"
itemscope
itemtype="https://schema.org/AggregateRating">
<span itemprop="ratingValue">4.0</span> stars based on
<span itemprop="reviewCount">35</span> reviews
</span>
<br />
Prep time: <time datetime="PT30M" itemprop="prepTime">30 min</time>
<br />
Cook time: <time datetime="PT1H" itemprop="cookTime">1 hour</time>
<br />
Total time: <time datetime="PT1H30M" itemprop="totalTime">1 hour 30 min</time>
<br />
Yield: <span itemprop="recipeYield">1 9" pie (8 servings)</span>
<br />
<span
itemprop="nutrition"
itemscope
itemtype="https://schema.org/NutritionInformation">
Serving size: <span itemprop="servingSize">1 medium slice</span><br />
Calories per serving: <span itemprop="calories">250 cal</span><br />
Fat per serving: <span itemprop="fatContent">12 g</span><br />
</span>
<p>
Ingredients:<br />
<span itemprop="recipeIngredient">Thinly-sliced apples: 6 cups<br /></span>
<span itemprop="recipeIngredient">White sugar: 3/4 cup<br /></span>
…
</p>
Directions: <br />
<div itemprop="recipeInstructions">
1. Cut and peel apples<br />
2. Mix sugar and cinnamon. Use additional sugar for tart apples. <br />
…
</div>
</div>
```
#### Result
{{EmbedLiveSample('Representing structured data for a recipe', '', '550')}}
## Specifications
{{Specifications}}
## See also
- [Other different global attributes](/en-US/docs/Web/HTML/Global_attributes)
- Other microdata related global attributes:
- [`itemid`](/en-US/docs/Web/HTML/Global_attributes/itemid)
- [`itemprop`](/en-US/docs/Web/HTML/Global_attributes/itemprop)
- [`itemref`](/en-US/docs/Web/HTML/Global_attributes/itemref)
- [`itemtype`](/en-US/docs/Web/HTML/Global_attributes/itemtype)