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?
You can write HTML5 with XHTML 1.0 syntax, since HTML5 permits XML syntax and it explicitly allows an XHTML 1.0 doctype as “legacy doctype” in the XHTML syntax.
Adding a data attribute is easy. Any HTML element can have any number of data attributes added to its opening tag. We simply type data- followed by the name of our attribute into the element's opening tag alongside any other attributes we're already using.
HTML <data> Tag.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With