Having to support HTML 4.01 and HTML5 makes this hard. You can’t use meta
-name
elements (would work for HTML 4.01, but they have to be registered for HTML5), you can’t use custom data-*
attributes (not allowed in HTML 4.01), you can’t use Microdata (only defined for HTML5+), you can’t use custom elements (only defined for HTML5+).
I can think of two ways.
script
element as data block
In HTML5, the script
element can also be used for data blocks. Examples: text/html
, text/plain
.
The HTML 4.01 spec doesn’t define it like that, but it should still be possible/valid (it’ll understand it as "script", but user agents are not expected to try to run it if they don’t recognize the content type as possible for scripts).
Drawback: The content is not part of the document’s DOM.
RDFa
It’s allowed in HTML 4.01 and HTML5 (you might have to adapt the DOCTYPE for the older HTML versions, e.g., for XHTML).
You can’t use custom elements, but you can add property
and content
attributes (for name-value pairs), and you could use typeof
for "items" (e.g., what you would use the element name for), and you can make use of meta
and link
elements (visually hidden by default) in the body
.
<div vocab="https://api.example.com/voc#" class="the-hidden-information">
<div typeof="Item-123">
<meta property="foo1" content="bar1" />
<meta property="foo2" content="bar2" />
</div>
<div typeof="Item-345">
<meta property="foo1" content="bar1" />
<link property="foo5" href="/some-url" />
</div>
</div>
(when using RDFa 1.0 instead of 1.1, you’d have to use xmlns
instead of vocab
)