Can Microdata be applied to any type of HTML element?

In all the examples on the Internet, I see the Microdata itemscope and itemtype properties for div elements, for example:

 <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="../movies/avatar-theatrical-trailer.html" itemprop="trailer">Trailer</a> </div> 

But is it possible to apply Microdata to any other item, in my case I want to apply it to a list item:

 <ul> <li 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="../movies/avatar-theatrical-trailer.html" itemprop="trailer">Trailer</a> </li> </ul> 

Are there any known issues with this?

+3
source share
3 answers

Simply put, yes. Take a look at the Google page yourself to see how they use it in different tags: https://support.google.com/webmasters/answer/176035?hl=en

+4
source

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:

Each HTML element can have an itemscope attribute.

Thus, each item can have itemscope . The following is said:

Items with the itemscope attribute may have the itemtype attribute specified by

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

Elements with the itemscope attribute and itemtype [...] attribute can also have the itemid attribute specified

If it has itemscope and itemtype , it can also have itemid . A:

Items with the itemscope attribute may have the itemref attribute specified by

If he has itemscope , he can have itemref .

Only itemprop missing. It is defined in Section 5.3 :

Each HTML element can have the itemprop attribute specified

So itemprop can also be used for each item.

(Note that Microdata (W3C note) refers to the HTML5 specification to determine what an “HTML element” is , so essentially an “HTML” element “means an HTML5 element.”

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

See 8.1 Content Models .

For instance:

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

... and some elements have special rules for determining the value of a property (when itemprop used)

See 5.4 Values .

For instance:

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

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

Here foobar s is 5 , not 10 :

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

And search engines should know this.

If Google or other search engine services support it, it cannot be definitely defined, since nothing can be guaranteed with certainty when it comes to third-party services that hide their code. Even if they (appear to be) supporting him today, we cannot know what will happen tomorrow. Therefore, such questions are usually not suitable for.

However, there is no reason to believe that search engines would not support it.

+8
source

Addendum to Jeremy Miller's answer:

Microdata essentially forms objects. In actual HTML, an element with the itemscope attribute contains all the microdata associated with it. In addition, the volume of each item with itemprop sufficient to contain all the data needed for this property.

Imagine replacing each itemscope element itemscope the element itself; and replacing each itemprop element itemprop the property itself and its value. (Think XML)

In your example, the element will look like this:

 <movie> <name>Avatar</name> <director>James Cameron</director> <genre>Science fiction</genre> <trailer>Trailer</trailer> </movie> 

This itemscope and itemprop can be applied to any suitable hierarchy of HTML elements, no matter what elements they are. The long-term answer is still yes, but I hope this helps you understand how microdata is interpreted.

In addition, I assume your example is from here , but I suggest you give at least paragraphs 1a-1d of quick reading.

+1
source

Source: https://habr.com/ru/post/954699/


All Articles