Custom Elements Donāt Require a Hyphen as a Separator
Scott Jehl reached out to help me resolve a conundrum in my post about what constitutes a valid custom element tag.
The spec says you can have custom elements with emojis in them. For example:
<emotion-š></emotion-š>
But for some reason the Codepen where I tested this wasnāt working.
Turns out, Iām not very good at JavaScript and simply failed to wrap everything in a try/catch.
Whatās funny about this is that <my-$0.02>
isnāt a valid custom element but <my-š²0.02>
is!
Anyhow, Iāve since updated that post and now things work as the spec says. All is good with the world.
But thatās not all.
In my convo with Scott, he pointed out that custom element tag names donāt need a hyphen as a separator of characters, they only need the hyphen.
This kinda blew my mind when I realized it. All this time Iād been thinking about the rules for custom elements wrong.
You arenāt required to have the hyphen as a separator:
<my-tag></my-tag>
Youāre just required to have it:
<mytag-></mytag->
Those are both valid custom element tag names!
Which means, if you have a really simple element and canāt think of a better name than an existing HTML element, you can do this:
<h1->My custom heading</h1->
Or this:
<p->My custom paragraph</p->
Or, I suppose, even this:
<ul->
<li>My custom unordered list</li>
<li>That still uses normal liās</li>
<li>Because why not?</li>
</ul->
Iām not saying you should do this, but I am saying you could ā you know, nothing ever went wrong doing something before stopping to thinking about whether you should.