Appearance
Mark up with RDFa Lite
ReferenceRDFa Lite is a small, easy to learn subset of RDFa that covers most structured data needs. It uses a handful of attributes that attach vocabulary meaning to existing HTML.
The core attributes
- vocab sets the default vocabulary for descendant elements, for example
https://schema.org/. - typeof declares the type of the current item.
- property names a property of the current item.
- resource assigns an identifier to an item so it can be referenced.
Steps
- Set the vocabulary and type. Add
vocabandtypeofto the container element.
html
<div vocab="https://schema.org/" typeof="Movie">
<h1 property="name">Avatar</h1>
<span property="director">James Cameron</span>
<span property="genre">Science fiction</span>
</div>Add properties. Mark each value with
property. The element content becomes the value, except foraandimgwhere thehreforsrcis used.Nest items with typeof. A property whose value is an entity gets a nested element with its own
typeof.
html
<div vocab="https://schema.org/" typeof="Product">
<span property="name">Executive Anvil</span>
<div property="offers" typeof="Offer">
<span property="price">119.99</span>
<meta property="priceCurrency" content="USD" />
</div>
</div>- Use content for machine values. As with Microdata, use the
contentattribute when the readable text and the machine value differ.
Done when
- The container declares both
vocabandtypeof. - Each value carries a
propertyattribute. - Validation confirms the item and its properties.
Notes
- RDFa Lite is a good choice when you are already familiar with RDFa or need the additional expressivity of the full RDFa standard later.
- For greenfield projects, JSON-LD is usually simpler to maintain.