I think not. I think the standard should be modified to simply allow us to use any attribute names we want. If you asked ESDiscuss if we should limit function name to start with f
and in function fMyFunction() {}
people would go nuts. I don’t see why HTML has to be different from that.
But, anyways, all browsers support this already, so it doesn’t matter so much (that’s why we can use any custom attributes we want on our custom elements, otherwise it wouldn’t be as fun). :}
I think that would just complicate things. Browsers currently let us put any attributes we want on elements, and I think that’s fine. It’s up to us to know whether the attribute we’re using is meant to do something (natively) or not. It’s like setting a property on an object in JavaScript: we can set it to whatever we please, and we understand that it’s possible setting the value might do something (and it’s up to us to know what that something is (i.e. read API documentation)).
People keep mentioning this for various parts of the HTML API, but to me this point it moot. Let us override anything we wish, and assume it is our responsibility to read API documentation before we blindly override everything. Programming languages are like that, and I think HTML should be too. For example, one argument against allowing us to define elements with names of already-existing elements is that “it would prevent the standard being able to add new ones”. I wholeheartedly disagree: browser could add anything they want, and users should beable to override them as they please. We can do it in JavaScript (for example, override the property of an object, in some cases the global object), so why not in HTML?
document.registerElement('img', BecauseThisIsMyAppAndIWantTo)
document.registerElement('monster', MonsterElement)
Because, why not? Simply saying that “browsers need to be able to introduce new elements” isn’t a good reason. If we allow native elements to be overridden, then my previous example proves that the feature is future-proof; for example, if browsers introduce a new element called <monster>
, the app that runs the previous code will not break because the <monster>
tag will continue to use the app author’s logic, not the browser’s native logic.
It would be like in JavaScript: if I have some code that overrides window.setInterval
with a custom function, no amount of updates to the browser’s native implementation will ever interfere with mine. Why not let HTML be as flexible and customizable (and as fun and pleasurable to work with) as JavaScript?
I think it is reasonable to relax the rules to the following:
- Custom attribute names can be anything, and same with custom element names.
- Put a hyphen in it if you feel like it, or don’t.
- Frameworks and libraries should choose to do whatever they want to do (like currently?)
- Be free.
I think that this list (it’s not really a list, since it really boils down to item 1) can be nicely coupled with the idea of encapsulating things such as custom elements (with any name and with any attributes) inside of ShadowDOM roots. The concept would be similar to what React has introduced: encapsulation of HTML elements (JSX) inside of components (classes that extend React.Component). In this case, the encapsulation of HTML happens inside Custom Elements using ShadowDOM roots. Let a component author decide for him/her-self what an <img>
tag means inside of his/her component. We can in React, and the concepts there have been proven based on React’s popularity, and based on the spawning of a number of libraries inspired similar to React.
In conclusion, restrictions beyond the native restrictions on element/attribute naming don’t provide much benefit. I’d love to see a day when we can override any element with out own, or make news ones with any name, and with component encapsulation using Custom Elements + ShadowDOM (or something similar, but ShadowDOM seems to be where it’s heading).
React and similar libraries are the embodiment of what the web does not yet have. I believe in the web’s ability to improve, and I’d love to see the day when HTML can be as flexible, as custom, and as modular as React components (or Angular directives, or Riot.js custom tags) so that we don’t need a 3rd-party library for such a thing. Well, the web doesn’t seem to have any plan for a feature whereby we can repeat elements based on an array of data like those 3rd-party libraries do, but that’s an idea for another day…