data- versus data:

I like the concept of the data-* attributes introduced with HTML5. I don’t like how they are implemented. Just one character had to be changed.

The data-* attributes “are intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements” (quoted from HTML5 spec). The author of a web page may use arbitrary attributes, whose names begin with data- followed by some more characters. For example, if you want to store something you call “mydata” within your HTML code you might use an attribute named “data-mydata”. Obviously the string “data-” is required to prevent conflicting attribute names. Accordingly “data-” is nothing else than a namespace prefix.

Namespaces? Yes, they’ve already been invented. Probably several times. For markup languages they have been invented/introduced by W3C more than a decade ago. Those namespaces use a prefix too. But it’s separated from the custom name by a  colon (:) not a dash (-). The mydata attribute would look like “data:mydata”. For the namespaces to be namespace spec compliant, the prefix must be declared in the HTML document. The authors of the HTML5 spec don’t seem to like that. Ok, but why the dash instead of the colon? What’s the problem to define the feature as “data:* attributes” in the HTML5 standard? With a dash, the data attributes can’t be specified in a DTD; with a colon, they can.

From my point of view it would be even easier to change the namespace spec in order to allow namespace prefixes that have not been declared. The rule could be: Every undeclared prefix gets a “temporary”, document wide unique identifier.

Some say, HTML5 can’t be expressed with a DTD/Schema. When it comes to data-* attributes, it looks like they first decided, HTML5 shall not be expressed in terms of XML/SGML, and later say it can’t.

This entry was posted on 03/06/2011 in critique, proposal and tagged , , . Bookmark the permalink. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

One Response to “data- versus data:”

  1. Niall Douglas Says:

    Hi,

    Just wanted to thank you for this site and your efforts to make a (X)HTML5 DTD. I didn’t really look into HTML5 when it was announced as nothing supports it, but when the search engines announced schema.org microdata I suddenly became a lot more interested. And I am quite simply *stunned* that they have deliberately chosen to break XML compatibility.

    I’m not saying HTML5 must equal XHTML5. What I am saying is that XHTML5 ought to be useful XML and as close a subset to HTML5 as is practical. Your post above about data- ought to be data: is a good example, though I’d prefer something like userdata: instead as it has less chance of namespace clash.

    Keep up the good work. I’ll be watching!

    Niall

 
Creative Commons License
HTML5 DTD by Stefan Mintert/Linkwerk GmbH is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.