Markdown

RDFa

RDFa is the Acronym for Resource Description Framework in Attributes

RDFa lets a publisher attach statements to elements already on the page. Software can then tell a headline from a byline, a date from a phone number, and a license link from an ordinary click, without a second copy of the facts kept only for machines.

Each statement is a triple in the RDF model: a subject, a relationship, and a value. A W3C specification defines how those triples are written as attributes. Vocabulary terms are written as a URL, so the same spelling cannot silently mean a headline in one vocabulary and a job role in another.

The attributes are defined for HTML and for host languages built on XML. An earlier edition of the rules covered XHTML only. The attributes do not change how a page looks. Browsers that do not understand them simply ignore them for display.

How the Attributes Work

A processor walks the elements and collects statements. The subject is the item being described. The relationship is a term from a vocabulary. The value is visible text, a normalized literal, or the address of a link. A parent can set a default vocabulary so child elements use short term names. A nested region can switch to a different vocabulary.

Many pages need only a type, a subject, and a handful of properties. The remaining attributes handle compact prefixes, a machine-oriented value beside friendlier visible text, and a datatype such as a date or a number.

AttributeRole
vocabSets the vocabulary address used to expand short term names on this element and its descendants.
typeofStates the type of the item. With no separate subject address, it also introduces a new item for the nested statements.
propertyNames the relationship. The value is usually the element’s visible text, or the address on an href or src attribute when one is present.
resourceGives the address of the item that statements inside the element describe. The address may be relative or absolute.
aboutNames the subject directly, including when that subject is not a new item created on the same element.
prefixMaps short prefixes to vocabulary addresses so compact names can draw on more than one vocabulary.
datatypeNames the form of a literal value, such as a date or a number, when text alone would be ambiguous.
contentSupplies the value for machines when the visible text should stay in a friendlier form.

Other Syntaxes for the Same Statements

The same kind of statement can be written with these attributes, with Microdata, or with JSON-LD. Terms from Schema.org can be expressed in any of the three. In the attribute form, each term sits on the element that shows the value. JSON-LD usually gathers the statements in a script block kept apart from the visible copy. Microdata uses its own attributes, including itemscope and itemprop, on the elements themselves.

For rich results, documentation from Google lists JSON-LD as the recommended format and also lists this attribute syntax and Microdata as supported. In HTML5 practice, the attribute syntax is the older of those approaches for that job. The documentation states a preference. It does not publish a count of pages using each format, so no adoption split is claimed here.

Patterns on a Page

  • Declare one vocabulary on a parent, then use short property names on the children. A nested element can name a different vocabulary for its own region.
  • Give every item in a listing its own subject so one title, author, or date is not applied to the whole page.
  • Name the relationship on a link when the address is the value, such as a license or a homepage, rather than leaving the click unlabeled for software.
  • Keep the visible text readable, and use a content value only to normalize something the reader can already see, such as a date. Add a datatype when the literal has a defined form.
  • Skip a subject address when a type alone should introduce a new item that has no public address. Properties inside that element belong to the new item.

A prefix map lets several vocabularies share one region without repeating long addresses, and a full term address can still appear beside a short name. The page stays readable as ordinary prose. The statements are explicit, so a processor does not have to guess them from font size or position.

Articles Tagged RDFa

View Additional Articles Tagged RDFa