Comment by xg15
12 hours ago
Whether you can or can't omit a closing element is one thing, but it seems like a useful thing to be able to quickly determine if some content is inside or outside a tag, so why complicate things?
(This is especially relevant with "void" tags. E.g. if someone wrote "<img> hello </img>" then the "hello" is not contained in the tag. You could use the self closing syntax to make this more obvious -- Edit: That's bad advice, see below.)
The inert self closing syntax is misleading, though, because if you use it for a non-void element then whatever follows will be contained within the tag.
e.g. how do you think a browser will interpret this markup?
A lot of people think it ends up like this (especially because JSX works this way):
but it's actually equal to this:
Ah, that's true. I think the WHATWG discouraged the syntax, so this might be why.
This is really easy to detect though, unlike arbitrary rules on what belongs on the inside of an unclosed tag.
I absolutely agree. Also, if you want to parse HTML as XML, it's a lot more reliable having it in a known 'good' format to begin with.
This is where I always end up as well. Just because you can do something doesn’t mean you should or shouldn’t.