Preferences

That rule doesn't work in reverse. If there's no dash it could be either.

So now you've got to try to enforce some practice of using hyphens in all tag names that used to be class names, even if they're a single word that has no place for a hyphen?

It's getting even more confusing now, you see? Not less.

Just use classes. That's what they're there for.


Only native elements can be a single word, you can't create a custom elements without a dash.
Let's be clear: this whole conversation isn't about custom elements. This is about formatting. Not web components.

You just use it (single word) and style it (CSS) and it works. You don't have to "create" anything.

So nothing's stopping anyone from using single-word elements. There's another comment here defending exactly that:

https://www.hackerneue.com/item?id=46418090

But it's bad practice. Just use classes. It's literally what they are designed for.

Aha fair enough, but yeah browsers often allow invalid HTML to just work. But that doesn't mean that the valid usage is somehow flawed. I can understand that the dash can be a bit of a weird rule if you're new to HTML. But I think it's an elegant way to allow users to create custom tags and have readable compact semantic HTML.

But yeah I also do see the confusion part, if a person new to HTML sees these custom tags being used it might think it can create one too and not realize it must contain a dash, and it would still work. So yeah in that sense, indeed it's confusing if you're unfamiliar with it.

But having multiple </div></div></div> at the end of a large block of HTML is also confusing, often resulting in closing too many / too few divs. Having </nav-item></nav-bar></main-header> is much better. So yeah it has it's pros and cons I guess.

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal