3

I have read the HTML5 specification, the microdata specification, and the WHATWG HTML5 (with microdata) specification. These are well written and easy to understand.

But now I read the schema.org Book specification, and came across snippets like the following:

<span itemprop="price" content="6.99">$6.99</span>
<span itemprop="inLanguage" content="en">English-language</span>
<span itemprop="name" content="Tolkien, J. R. R. (John Ronald Reuel)">
  J. R. R. Tolkien</span>

Apparently (compare with the JSON version), the values of these microdata properties are the values of the content attributes of the span elements. (Of course, if there is no content attribute, the value is instead the textContents of the span element.)

But I cannot find any support for this practice in the HTML and microdata specifications. In fact, I cannot even find any evidence that there is a content attribute on span elements at all!

  • The microdata specification doesn't say anything about a span content attribute when it gives the rules for values. [Unless 'the element's textContent' is overridden by the content attribute, but I cannot find any support for this either.]

  • Not even the full WHATWG HTML5+microdata specification supports the claim that there is a content attribute on span (see The span element and Global attributes).

So, I suppose the schema.org example is non-conforming. But is it also plain wrong? If not, where does this practice come from, and how accepted is it?

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384

2 Answers2

6

Yes, this is wrong. Neither Microdata nor HTML5 define a content attribute for the span element.

Several people wanted to use it, see for example the code in these questions:

I’m not sure where exactly this confusion is coming from.

(It doesn’t help that Google’s Structured Data Testing Tool incorrectly uses the content attribute instead of the element content; but at least all other Microdata parsers seem to do it correctly.)

Maybe some people got confused because RDFa (but not Microdata) defines and allows the content attribute for span. See HTML+RDFa’s Extensions to the HTML5 Syntax:

For the avoidance of doubt, the following RDFa attributes are allowed on all elements in the HTML5 content model: @vocab, @typeof, @property, @resource, @prefix, @content, @about, @rel, @rev, @datatype, and @inlist.

Community
  • 1
  • 1
unor
  • 92,415
  • 26
  • 211
  • 360
  • I filed an [issue](https://github.com/rvguha/schemaorg/issues/184) about this Schema.org example. – unor Nov 23 '14 at 13:13
  • "Plus one" for information on parser behaviour and the RDFa confusion origin hypothesis. – Andreas Rejbrand Nov 23 '14 at 13:14
  • This documentation example does show an `@content` attribute with a `` tag, despite the current standard: https://support.google.com/webmasters/answer/146898 . Is there no solution for this in (other) microdata (parsers)? – Wes Turner Dec 16 '14 at 15:39
  • To reiterate the answer above with a link to the syntax spec, `@content` does not have these restrictions in RDFa: http://www.w3.org/TR/rdfa-syntax/#A-content """If some displayed text is different from the actual 'value' it represents, a more precise value can be added using `@content`. A value can also optionally be typed using `@datatype`""" – Wes Turner Dec 16 '14 at 15:41
3

(Sorry, I didn't have enough reputation to post a comment.)

We're at the end of 2017 now. Somehow, the MDN webdocs (https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/itemprop) and the schema docs (http://schema.org/telephone) still propose to use a content attribute on span using microdata. No html5 validator will accept this of course.

Johannes Müller
  • 5,581
  • 1
  • 11
  • 25
Luneya
  • 31
  • 3