How does the RDFa vocab attribute simplify Schema.org markup?

The Citead team, updated

In short. RDFa vocab maps short Schema.org type and property names to full IRIs within an HTML scope.

Definition: The RDFa vocab attribute sets a default vocabulary for a part of an HTML document. When property or typeof contains a short term such as name or Product, RDFa combines that term with the vocabulary IRI to produce the full IRI used in the RDF data.

Key facts

  • The W3C RDFa 1.1 Primer is a Working Group Note dated 17 March 2015.
  • The Primer says that vocab lets an author declare one vocabulary for a chunk of HTML, so repeated full URLs can become short terms.
  • RDFa Core defines vocab as an IRI that supplies the mapping used when a term appears in an attribute value.
  • The same specification permits property and typeof to contain terms, CURIEs, or absolute IRIs.
  • Schema.org's data model documents RDFa Lite as a syntax for all of Schema.org and adds vocab="https://schema.org/" to an enclosing element.

Why does vocab shorten Schema.org markup?

An IRI is the web identifier used for a vocabulary term. Without a default vocabulary, an RDFa author can write a complete IRI in every property value. The W3C Primer describes this as error prone and tedious when a page mainly uses one vocabulary. The vocab attribute lets the author declare that vocabulary once for a section, then use terms such as name, image, and offers in descendant markup.

For Schema.org, the enclosing value is commonly https://schema.org/. RDFa then interprets Product and name as terms in that vocabulary. The short form changes the attribute values used in the HTML while the RDF statements retain the vocabulary's full identifiers.

<div vocab="https://schema.org/" typeof="Product">
  <img property="image" src="dell-30in-lcd.jpg" />
  <span property="name">Dell UltraSharp 30" LCD Monitor</span>
</div>

Schema.org's data model uses this Product example to show the RDFa Lite form of its markup.

How does RDFa expand a term?

RDFa Core describes vocab as the mapping used when a term is referenced in an attribute value. During term processing, if a local default vocabulary exists, the processor obtains the IRI by concatenating that vocabulary value and the term. Thus, typeof="Product" under vocab="https://schema.org/" resolves from the two strings to the Schema.org Product IRI, and property="name" resolves in the same way.

The rule applies to the attributes that accept terms. RDFa Core lists property and typeof among attributes that allow one or more terms, CURIEs, or absolute IRIs. A CURIE uses a declared prefix, while an absolute IRI is already complete. If a term has neither a default vocabulary nor a matching local term mapping, the specification says it has no associated IRI and must be ignored.

This term resolution is part of ordinary RDFa processing. RDFa Core separately describes RDFa Vocabulary Expansion as an optional step that can add inferred triples from vocabulary relationships after the output graph has been generated. The vocab attribute's basic job here is to resolve the short names in the markup.

Where does the default vocabulary apply?

The W3C Primer says that vocab can appear on any HTML element and that its effect covers the elements below that point. A page can therefore place the mapping on a wrapper around one item or on a larger section. A nested vocab value changes the local mapping for that element and its descendants.

The same Primer also says that default vocabularies and full URIs can be mixed at any time. This allows a Schema.org section to keep short terms for its main vocabulary while a property from another vocabulary uses its complete IRI or a separately scoped vocab value.

What does Schema.org change from Microdata?

Schema.org's data model states that all of Schema.org can be used with RDFa Lite and that the RDFa Lite form looks almost like its Microdata form. Its mapping replaces itemprop with property, drops itemscope, replaces itemtype with typeof, and adds vocab="https://schema.org/" to the body or another enclosing tag. The default vocabulary is therefore the part that lets the type and property names stay short after the syntax is converted.

FAQ

Does vocab change what visitors see?

No. The W3C Primer states that RDFa-specific attributes have no effect on the visual display of HTML content. They add machine-readable structure to existing markup.

Can a page combine Schema.org terms with full IRIs?

Yes. The same Primer says that default vocabularies and full URIs can be mixed at any time. A full IRI can be used where the surrounding default vocabulary would identify a different term.

Is vocab the same as RDFa Vocabulary Expansion?

No. vocab supplies the local mapping used to resolve terms during RDFa processing. RDFa Core describes RDFa Vocabulary Expansion as an optional later step for adding triples inferred from vocabulary relationships.

Sources

  1. W3C, "RDFa 1.1 Primer - Third Edition", 17 March 2015
  2. W3C, "RDFa Core 1.1 - Third Edition", 17 March 2015
  3. Schema.org, "Data model", undated

Check how a page reads to answer engines. Open the GEO score analyzer

Test a page and see what to fix first

The analysis usually takes less than 10 seconds and needs no account.

400,000+ pages scored in the public benchmark