Mobile app version of vmapp.org
Login or Join
BetL925

: Are Microdata attributes valid on any element? Is it valid to add Microdata attributes (e.g., using the Schema.org vocabulary), such as itemprop="name", to HTML elements that aren’t span or div?

@BetL925

Posted in: #Html5 #Microdata

Is it valid to add Microdata attributes (e.g., using the Schema.org vocabulary), such as itemprop="name", to HTML elements that aren’t span or div?

For example:

<h2 class="product_name" itemprop="name">Baseball Glove</h2>

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @BetL925

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

Yes, you can use every HTML5 element for Microdata …

Microdata defines 5 new attributes for HTML5:


itemid
itemprop
itemref
itemscope
itemtype


Let’s see where they can be used. Section 5.2 says:


Every HTML element may have an itemscope attribute specified.


So every element can have itemscope. Further on it says:


Elements with an itemscope attribute may have an itemtype attribute specified


So if it has itemscope (and we learned that every element can have it), it can have itemtype, too. Next:


Elements with an itemscope attribute and an itemtype attribute […] may also have an itemid attribute specified


If it has itemscope and itemtype, it can have itemid, too. And:


Elements with an itemscope attribute may have an itemref attribute specified


If it has itemscope, it can have itemref.

Only itemprop is missing now. It’s defined in Section 5.3:


Every HTML element may have an itemprop attribute specified


So itemprop can also be used on every element.

(Note that Microdata (W3C Note) refers to the HTML5 spec for defining what a "HTML element" is, so essentially "HTML element" means "HTML5 element".)

… but some elements get a different content model (when itemprop is used)

See 8.1 Content models.

For example:


href becomes a required attribute for a and area
data becomes a required attribute for iframe
the attributes name, http-equiv and charset are no longer allowed on meta



… and some elements have special rules for determining the property value (when itemprop is used)

→ See 5.4 Values.

For example:




Special rules for links. Here foobar’s value is the URL example.com/, not the string Link:

<a href="http://example.com/" itemprop="foobar">Link</a>

Here foobar’s value is 5, not 10:

<data value="5" itemprop="foobar">10</data>






(Taken from my answer to a closed question on SO.)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme