Can I Use Multiple ItemProps in a Span Tag for schema.org Rich Snippets?
Asked Answered
M

2

39

Let's say I have the following sentence I want to add rich snippets to:

I live and work in New York

Since New York is both my residency and the city where I work in, I would theoretically want to tag the line like this using schema.org standards:

<div itemscope itemtype = 'http://schema.org/Person'>I live and work in 
<span itemprop = 'homeLocation'  itemprop = 'workLocation'>New York</span></div>

Is it valid to have 2 itemprops in one span tag? If not, will the below work?

<div itemscope itemtype = 'http://schema.org/Person'>I live and work in 
<span itemprop = 'homeLocation'><span itemprop = 'workLocation'>New York
</span></span></div>
Metagenesis answered 7/1, 2013 at 15:32 Comment(1)
May I ask why you rolled back the edit?Elison
E
59

The usual HTML way would be to use one attribute and separate several values with space characters.

Looking into the Microdata specification, you’ll notice that this is the case for the itemprop attribute, too:

The itemprop attribute, if specified, must have a value that is an unordered set of unique space-separated tokens […]

So this should be correct:

<div itemscope itemtype="http://schema.org/Person">
  I live and work in <span itemprop="homeLocation workLocation">New York</span>
</div>

(Note: If using itemprop values as CSS selector, use [att~=val] instead of [att=val].)

Elison answered 8/1, 2013 at 13:56 Comment(3)
what about property, does that the same?Columniation
@deadManN: Yes, RDFa’s property attribute can also take multiple values, separated by white space.Elison
You noted a valuable technique using attribute selectors. Those who want to style either or, or both, can use [attr*=value] with case-insensitivity, e.g. [itemprop*=location i].Edessa
M
1

The first snippet of code I posted does not work, but the second does. Google has a rich snippets page tester which is pretty useful for code validation

Metagenesis answered 7/1, 2013 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.