itemscope
is a boolean
global attribute
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
, is used to specify the valid URL of a vocabulary (such as
schema.org
) that describes the item and its properties context. In each of the following examples, the vocabulary is from
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
.
注意:
Find more about
itemtype
attributes at
http://schema.org/Thing
The following example specifies the
itemscope
attribute. The example specifies the
itemtype
as "http://schema.org/Movie", and specifies three related
itemprop
属性。
<div itemscope itemtype="http://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>
The following table shows the structured data from the preceding example.
| itemscope | Itemtype | Movie | |
| itemprop | (itemprop name) | (itemprop value) | |
| itemprop | director | James Cameron | |
| itemprop | genre | Science Fiction | |
| itemprop | 名称 | Avatar | |
| itemprop | https://youtu.be/0AY1XIkX7bY | Trailer | |
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
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.
There are four
itemscope
attributes in the following example. Each
itemscope
attribute sets the scope of its corresponding
itemtype
属性。
itemtype
s,
Recipe
,
AggregateRating
,和
NutritionInformation
in the following example are part of the
schema.org
structured data for a recipe, as specified by the first
itemtype
, http://schema.org/Recipe.
<div itemscope itemtype="http://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="http://schema.org/Person"> <span itemprop="name">Carol Smith</span> </span> </p> <p> Published: <time datetime="2009-11-05" itemprop="datePublished">November 5, 2009</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="http://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 hou</time>r<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="http://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>
The following is an example rendering of the preceding code example.
| itemscope | itemtype | Recipe | |
| itemprop | 名称 | Grandma's Holiday Apple Pie | |
| itemprop | image | https://c1.staticflickr.com/1/30/42759561_8631e2f905_n.jpg | |
| itemprop | datePublished | 2009-11-05 | |
| itemprop | description | This is my grandmother's apple pie recipe. I like to add a dash of nutmeg. | |
| itemprop | prepTime | PT30M | |
| itemprop | cookTime | PT1H | |
| itemprop | totalTime | PT1H30M | |
| itemprop | recipeYield | 1 9" pie (8 servings) | |
| itemprop | recipeIngredient | Thinly-sliced apples: 6 cups | |
| itemprop | recipeIngredient | White sugar: 3/4 cup | |
| itemprop | recipeInstructions | 1. Cut and peel apples 2. Mix sugar and cinnamon. Use additional sugar for tart apples. | |
| itemprop | author [Person] | ||
| itemprop | 名称 | Carol Smith | |
| itemscope | itemprop[itemtype] | aggregateRating [AggregateRating] | |
| itemprop | ratingValue | 4.0 | |
| itemprop | reviewCount | 35 | |
| itemscope | itemprop[itemtype] | nutrition [NutritionInformation] | |
| itemprop | servingSize | 1 medium slice | |
| itemprop | calories | 250 cal | |
| itemprop | fatContent | 12 g | |
注意 : A handy tool for extracting microdata structures from HTML is Google's Structured Data Testing Tool . Try it on the HTML shown above.
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML Microdata
The definition of 'itemscope' in that specification. |
工作草案 | |
|
HTML 实时标准
The definition of 'itemscope' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
itemscope
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
完整支持
<a>
<abbr>
<acronym>
<address>
<applet>
<area>
<article>
<aside>
<audio>
<b>
<base>
<basefont>
<bdi>
<bdo>
<bgsound>
<big>
<blink>
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center>
<cite>
<code>
<col>
<colgroup>
<command>
<content>
<data>
<datalist>
<dd>
<del>
<details>
<dfn>
<dialog>
<dir>
<div>
<dl>
<dt>
<element>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font>
<footer>
<form>
<frame>
<frameset>
<h1>
<head>
<header>
<hgroup>
<hr>
<html>
<i>
<iframe>
<image>
<img>
<input>
<ins>
<isindex>
<kbd>
<keygen>
<label>
<legend>
<li>
<link>
<listing>
<main>
<map>
<mark>
<marquee>
<menu>
<menuitem>
<meta>
<meter>
<multicol>
<nav>
<nextid>
<nobr>
<noembed>
<noframes>
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<picture>
<plaintext>
<pre>
<progress>
<q>
<rb>
<rp>
<rt>
<rtc>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<shadow>
<slot>
<small>
<source>
<spacer>
<span>
<strike>
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<template>
<textarea>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt>
<u>
<ul>
<var>
<video>
<wbr>
<xmp>
<input>
类型
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">