Hacker News new | ask | show | jobs
by underwater 2646 days ago
HTML doesn't require a closing slash, but without it needs to be context-aware and maintain a whitelist of tags that are self closing (one effect of this is that custom elements can never be self closing).

It's not really surprising that a developer would gravitate towards an encoding that is not dependent on maintaining a whitelist of tags, because that is the solution that intuitively feels more "correct".

3 comments

Completely agree. If you want a generic parser for HTML-like tags, templates or anything where the context isn't a full HTML page, you definitely want syntactically correct/valid markup.
Too bad the closing slash doesn't do anything. <script src="..." /> will break horribly if you try to use it. Everything still depends on the whitelist.
If one needs a closing slash to be reminded which of the five or so tags are self closing, one has far more issues than needing a closing slash.
My point is that not that remembering things is hard, it's that it feels like a hack. Developers gravitate to solutions that feel elegant.
Putting the slash in, as I said, is there for backwards compatibility only, not elegance, and it could be removed at any time since this backwards compatibility issue no longer exists, or is of minor consequence nowadays.

It is far, far better to read and follow the standard specification and not follow a whim that makes you feel good. These are the things that will burn you first.

Issues like being a parser?