Search code examples
htmlseoschema.orgmicrodatastructured-data

Is there a way to have markup as the value to schema.org itemprop?


Is there a way to have markup as the value to a schema.org itemprop node? E.g. this works:

<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 can you make this work:

<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"> <p>Science</p> <h2>fiction</h2></span>      <<====
  <a href="../movies/avatar-theatrical-trailer.html" itemprop="trailer">Trailer</a>
</div>

Solution

  • The HTML spec defines what the property value is of an element with an itemscope attribute, and it says for elements other than meta, audio, embed, iframe, img, source, track, video, a, area, link, object, data, meter, or time, “The value is the element's textContent“.

    So the HTML spec requires consumers of microdata markup to ignore markup inside the span element in <span itemprop="genre"> <p>Science</p> <h2>fiction… and just use the text.