Tuesday, October 3, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  149] [ 7]  / answers: 1 / hits: 63912  / 15 Years ago, sun, june 14, 2009, 12:00:00

Recently I have been reading more and more about people using custom attributes in their HTML tags, mainly for the purpose of embedding some extra bits of data for use in javascript code.

I was hoping to gather some feedback on whether or not using custom attributes is a good practice, and also what some alternatives are.

It seems like it can really simplify both server side and client side code, but it also isn't W3C compliant.

Should we be making use of custom HTML attributes in our web apps? Why or why not?

For those who think custom attributes are a good thing: what are some things to keep in mind when using them?

For those who think custom attributes are bad thing: what alternatives do you use to accomplish something similar?

Update: I'm mostly interested in the reasoning behind the various methods, as well as points as to why one method is better than another. I think we can all come up with 4-5 different ways to accomplish the same thing. (hidden elements, inline scripts, extra classes, parsing info from ids, etc).

Update 2: It seems that the HTML 5 data- attribute feature has a lot of support here (and I tend to agree, it looks like a solid option). So far I haven't seen much in the way of rebuttals for this suggestion. Are there any issues/pitfalls to worry about using this approach? Or is it simply a 'harmless' invalidation of the current W3C specs?

More From » html


HTML 5 explicitly allows custom attributes that begin with data. So, for example, <p data-date-changed=Jan 24 5:23 p.m.>Hello</p> is valid. Since it's officially supported by a standard, I think this is the best option for custom attributes. And it doesn't require you to overload other attributes with hacks, so your HTML can stay semantic.

Source: http://www.w3.org/TR/html5/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes

[#99320] Wednesday, June 10, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 15
Total Questions: 101
Total Answers: 94

Location: Liechtenstein
Member since Fri, Sep 11, 2020
3 Years ago
mckinley questions
Sun, Oct 17, 21, 00:00, 2 Years ago
Tue, Jun 15, 21, 00:00, 2 Years ago
Thu, Apr 8, 21, 00:00, 3 Years ago