Relaxing restrictions on custom attribute names


I wouldn’t. I believe the data- prefix has not been used in libraries like Angular just because it’s too long while underscore is certainly not.

But as an option, we could standardize a set of widely-used prefixes such as ng- (like how -webkit- prefixed CSS features are now standardized) and require underscore for any other/new custom attributes.


What if we restrict allowed prefixes to 2 characters + data-? That prevents most (all?) clashes with SVG attributes, and still gives us 676 more prefixes to use, reducing both risk of conflicts, and verbosity. I actually checked, and there are no CSS properties that start with 2 letters and a hyphen.


Fwiw, I’ve posted a proposal about making underscore-prefixed attributes formally valid in the whatwg/html GitHub repository. (Editing my corresponding comment above is now unavailable.)


I prefer this approach over underscores. It’s a great idea that immediately improves current situation and can be widened in the future if needed. Worth posting to whatwg as an alternative?

@leaverou And maybe also allow any attributes if they include non-alphanumeric, non-hyphen characters (Angular2’s [] and () attributes)? Not critical for the first iteration though.


Fwiw, with the generic _ prefix, we would have unlimited number of possible prefixes: _foo-, _bar-, _hello-, _world-, _anybody-, _home-, etc.