-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
It makes sense to make underscore-prefixed (_) custom HTML attributes formally valid:
<div _foo="bar" _lorem="ipsum" _boolean></div>
Facts and advantages
- Works in all existing browsers, no implementor efforts needed, it’s solely about formal validity.
- 100% issue-free and future-proof: standard attribute names will certainly never start with underscore.
- One-character long (5 times shorter than
data-). - Generic prefix with no specific constrained meaning unlike
data-(custom attributes are for data to the same extent as all standard attributes are) or with any other letter-based prefix likemy-. - Provides a way to use unlimited number of prefixes needed (and only if needed) for specific web app.
- There was some acceptance (namely by Lea Verou, Alexander Farkas, Taylor Hunt aka tigt, and Martin Janecke aka prlbr) of this idea in a related thread at the WICG forum.
- As a bonus, hyphen-free attribute names are easily selectable entirely via double click in code editors.
The data- prefix is omitted/ignored in practice
The currently allowed data- prefix is in fact too long (5-times longer than _) and therefore just omitted/ignored in practice (e. g. the Angular JS library uses ng-* attributes), so HTML markup inevitably gets invalid anyway (and not future-proof compared with the underscore prefix).
No interrelation with data- and dataset
Underscore-prefixed attributes should not affect data- prefixed attributes and/or the dataset DOM property in any way, and vice versa. _ and data- prefixed attributes should just coexist.
Hyphen prefix as an option
Alternatively, hyphen (-) prefix could be used instead of underscore (_), but actually, both work in all browsers, both are future-proof, so both should be formally valid. Underscore would just be enough.
Also, from the two, the underscore prefix is reportedly the only XML-compatible option that is also confirmed by Simon Pieters (@zcorpan).