3

From Google Developers I took this example for Microdata to include the site name in search results:

<head itemscope itemtype="http://schema.org/WebSite">
    <title itemprop='name'>Your WebSite Name</title>
    <link rel="canonical" href="https://example.com/" itemprop="url">
</head>

With the W3C Validator I got this error message:

Error: Attribute itemprop not allowed on element link at this point.

What would be the correct markup for this?

unor
  • 92,415
  • 26
  • 211
  • 360
roland
  • 900
  • 12
  • 25

1 Answers1

5

According to WHATWG’s HTML, link can’t have a rel and an itemprop attribute. According to W3C’s Microdata (which is a Note that no longer gets updated), both attributes can be used together. See my question 'itemprop' and 'rel' attributes on same element for details.

So if you want to conform to both specifications, you would have to duplicate the link element:

<head itemscope itemtype="http://schema.org/WebSite">
    <title itemprop="name">Your WebSite Name</title>
    <link itemprop="url" href="https://example.com/">
    <link rel="canonical" href="https://example.com/">
</head>
Community
  • 1
  • 1
unor
  • 92,415
  • 26
  • 211
  • 360
  • Ok, Google's example is wrong? Visual Studio give me a warning that `` needs a rel attribute, but it works. Does it make sense to separate "canonical" in a second ``? – roland Oct 17 '15 at 09:52
  • @roland: Google’s example is only wrong according to one Microdata spec, but valid according to the other. -- The fact that Visual Studio reports a `link` without `rel` as invalid is an error: in HTML5+Microdata, it’s perfectly fine to not have a `rel` attribute. -- Having a separate `link` makes sense if you want to conform to WHATWG’s version of Microdata (if you don’t care about that version, you could keep using only one `link`). – unor Oct 17 '15 at 13:49
  • 1
    To be clear on the W3C HTML Checker behavior with regard to Microdata: It checks [the requirements for Microdata in the HTML Living Standard](https://html.spec.whatwg.org/multipage/microdata.html#microdata), which is now the only spec that normatively asserts any requirements for Microdata at all. So it’s accurate to state that the old W3C Microdata document is no longer relevant (as a Note, it doesn’t assert any normative requirements) and so if you use Microdata and want to conform to the only current normative requirements for it, you must follow the rules in the HTML Living Standard. – sideshowbarker Oct 19 '15 at 01:13