9

Does anyone know how the HTML5 data attributes (data-*) can be implemented in XHTML without rendering the markup as invalid?

Is there a custom namespacing hack that would allow this on existing HTML elements?

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
matsko
  • 21,895
  • 21
  • 102
  • 144

2 Answers2

8

You could use XHTML5. Then your mark-up would be XML, and valid XHTML5.

I think you could also use XML namespacing to use them on XHTML1 — I’m not very familiar with XML, so I’m not sure.

I think that both of these methods technically require you to serve your pages as XML (instead of text/html), which Internet Explorer doesn’t support. But I suspect they’d work just fine in browsers even if you didn’t.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
  • I've seen a suggestion for this that for XHTML 1.0/1.1 you could maybe extend the DTD with a custom namespace (e.g. mycorp:data-foo="bar") and that will validate if you reference that DTD in the !DOCTYPE element... but moving XHTML5 is probably a better move :-). – Iain Collins Feb 29 '12 at 15:16
  • 1
    @IainCollins: yeah, I don’t know much about custom DTDs, but I think on the open web they’re generally a bad idea — they’d put IE 6 into Quirks Mode,for example. – Paul D. Waite Feb 29 '12 at 15:39
0

I don't know if this is a general solution, but it worked for me:

<ul data-clearing="">

Ie. just append ="" to make it a valid XML attribute.