How does RDFa content provide a machine-readable property value?

The Citead team, updated

In short. RDFa uses content as the literal property value when it is present, taking precedence over the element's displayed text.

Definition: RDFa's content attribute supplies an explicit literal value for a property. It lets an element display one string while an RDFa processor reads another value from the same element.

Key facts

  • The W3C RDFa Primer describes RDFa as HTML attributes that add machine-readable hints to visual information.
  • RDFa Core 1.1 defines content as a CDATA string that supplies machine-readable content for a literal object.
  • HTML+RDFa 1.1 allows the RDFa content attribute on all elements in the HTML5 content model.
  • RDFa Core gives the content value precedence over the element's inline content when both are present.

How does content override displayed text?

RDFa uses the element's textual content as the property value by default. The Primer's example uses a date: the page can show 10th of September, 2011, while the property value remains the machine-readable string 2011-09-10.

<span property="http://purl.org/dc/terms/created" content="2011-09-10">10th of September, 2011</span>

The property attribute identifies the predicate. The content attribute instructs the RDFa processor to use its value instead of the element's textual content, so the visible date and the extracted literal serve different readers. The Primer says that this produces the same RDF structure as the version that displays the machine-oriented date.

RDFa Core describes the same precedence normatively. When property is present and no resource attribute supplies an IRI object, the processor creates an object literal. For a plain or typed literal, it uses content when present; otherwise it concatenates descendant text nodes in document order.

What kind of value can the attribute carry?

The Core specification defines content as a CDATA string for a literal. A datatype attribute can give that literal a datatype, as in the specification's date example:

<span property="cal:dtstart" content="2015-09-16T16:00:00-05:00" datatype="xsd:dateTime">
  September 16th at 4pm
</span>

The generated triple contains the value 2015-09-16T16:00:00-05:00 with the xsd:dateTime datatype. The displayed wording stays readable, while the literal carries the value selected by the markup.

HTML+RDFa adds a host-language rule for the HTML time element. The datetime attribute supplies the current property value unless content is present on the same element. When both attributes are absent on time, the processor acts as if datetime contains the element's text value.

What should a page author check?

The value in content is an attribute string, so RDFa Core says its use prohibits rich markup in the literal. When the inline content already represents the object accurately, the specification recommends relying on that content instead of duplicating it in content. A value that needs markup belongs to the RDFa XML literal mechanism using datatype="rdf:XMLLiteral".

For HTML documents, HTML+RDFa lists content among the RDFa attributes allowed on all elements in the HTML5 content model. It also requires content when a meta element carries property, which supports header metadata such as a plain literal without visible body text.

FAQ

What does an RDFa processor read when content and visible text differ?

It reads the content value for the literal when property is present. The visible text remains the page content shown to readers.

It supplies a literal value. RDFa Core treats an element with property and no resource attribute as an object literal, while attributes such as href, resource, or src supply IRI resources.

Can content describe a date in a readable way?

Yes. The Primer pairs a readable date with content="2011-09-10", and RDFa Core pairs displayed text with a typed xsd:dateTime value.

Sources

  1. World Wide Web Consortium, "RDFa 1.1 Primer - Third Edition", 17 March 2015
  2. World Wide Web Consortium, "RDFa Core 1.1 - Third Edition", 17 March 2015
  3. World Wide Web Consortium, "HTML+RDFa 1.1 - Second Edition", 17 March 2015

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