2

I wonder if it makes any difference whether I markup an item on my site like this:

<h1 itemprop="name"><a href="some-page.html">Joe Doe</a></h1>

or like this:

<h1><a href="some-page.html" itemprop="name">Joe Doe</a></h1>
3

It depends on the element.

In your example, the name value isn’t the same. In the first snippet it’s the string "John Doe", in the second snippet it’s the relative URL Joe Doe (i.e., not what you want to convey). It’s because of the a element.

URL values

All elements that generate URL values if they have the itemprop attribute:

  • Elements with src attribute:
    audio, embed, iframe, img, source, track, video
  • Elements with href attribute:
    a, area, link
  • Elements with data attribute:
    object

If the value is a URL, you have to use one of these elements.

Text values

All other elements generate text values. If you nest them, it doesn’t make a relevant difference on which level you specify the itemprop element: the value will be the textContent of all nested elements (example in this answer).

But note that some of the text value elements use attributes instead of the element content, so if you specify the itemprop attribute on these elements, the nested elements are ignored:

  • Elements with content attribute:
    any
  • Elements with value attribute:
    data, meter
  • Elements with datetime attribute:
    time

(per the Microdata Working Draft from 2018-04-26)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.