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>

1 Answer 1

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 agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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