Greg Gum Greg Gum - 2 months ago 6x
HTML Question

Is there a reason not to use a custom "comment" attribute?

Is there a reason not to do the following?

<div comment="start display area">

I like to add notes, and this seems like an ideal way to do it.

I know I could do this as well:

<!--Start display area-->

The first syntax just seems cleaner to me. The issue I run into with
Is that sometimes, I do want to comment out an area of HTML for debugging purposes. That doesn't work when there are comment strings in there.

I found this much earlier discussion on it:


You should use data attributes. Data attributes are designed exactly for what you're intending to do:

HTML5 is designed with extensibility in mind for data that should be associated with a particular element but need not have any defined meaning. data-* attributes allow us to store extra information on standard, semantic HTML elements without other hacks such as non-standard attributes, extra properties on DOM, or setUserData.

Your div would look like:

<div data-comment="start display area">