Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use HTML5 Data Attributes in XHTML?

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?

like image 591
matsko Avatar asked Jul 19 '10 23:07

matsko


People also ask

Does HTML5 allows use of xhtml?

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.

How do you use data attributes in HTML?

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.

Which tag is used for data attribute in HTML?

HTML <data> Tag.


1 Answers

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.

like image 109
Paul D. Waite Avatar answered Sep 18 '22 15:09

Paul D. Waite