3 ms·
> But you cannot write <div id="mydiv" />. Sure you can. And exactly as with <br/> the / is ignored. Ignored means exactly that. HTML does not have xml-style
by masklinn 5y ago
> But you cannot write <div id="mydiv" />.
Sure you can. And exactly as with <br/> the / is ignored.
Ignored means exactly that. HTML does not have xml-style self-closing tags at all.
> for seemingly no reason.
The reason is pretty simple: there were no self/closing tags in SGML, so there were no self-closing tags in the mangled mess browsers made of it.
The goal of the HTML5 parser effort was to create an interoperable and backwards compatible parsing algorithm. Adding self-closing tags to the langage would have tin counter to that goal and would definitely have broken existing code unnecessarily, even though it might have been convenient in some cases.
- deleted 5y ago[deleted]
- saurik 5y ago>> But you cannot write <div id="mydiv" />. > Sure you can. And exactly as with <br/> the / is ignored. Obviously, the phrase "you cannot write" has the context "as a shorthand for self-closing the tag", and doesn't deserve some pedantic "of course you can do that, it just doesn't do what you hoped it would" response :/. To really be pedantic about it: SGML actually had a feature similar to this feature and HTML specified it; however, the syntax "<br/" was a valid way to write that tag (technically an open tag, but due to the DTD it would auto close) and the ">" after would get rendered... not ignored (and in fact might even cause the document to fail if that > was in a disallowed context of a strict document). https://jkorpela.fi/html/empty.html https://jkorpela.fi/html/empty.html Ironically, the W3's comment on this is to discourage its usage "until widely deployed", as they have essentially always specified stuff no one implemented correctly (lol). https://www.w3.org/MarkUp/html3/HTMLandSGML.html https://www.w3.org/MarkUp/html3/HTMLandSGML.html
- El_RIDO 5y agoMy workaround for this is to write XHTML 5. Now, that standard AFAIK never materialized, but modern browsers will still happily use their XML parser if you serve the document as application/xhtml+xml instead of their default (slower) tag-soup parser to create a DOM-tree out of it and after that their HTML 5 support ensures that they render it correctly. If and when browsers drop their XML parser, I hope they will just parse these docs as HTML and only then would I loose the option of self-closing tags.
- LinAGKar 5y agoIt didn't "never materialize". It's part of the HTML5 spec (although it's not called XHTML anymore, it's just HTML5 with XML syntax): https://html.spec.whatwg.org/#the-xhtml-syntax https://html.spec.whatwg.org/#the-xhtml-syntax
- captainmuon 5y ago> Ignored means exactly that. HTML does not have xml-style self-closing tags at all. You are answering my complaint by repeating the fact that I complained about? :-D > The goal of the HTML5 parser effort was to create an interoperable and backwards compatible parsing algorithm. Adding self-closing tags to the langage would have tin counter to that goal and would definitely have broken existing code unnecessarily, even though it might have been convenient in some cases. I'd wager that in pre-HTML5 code, the overwhelming amount of cases of <div /> were supposed to mean <div></div> and not <div>.... Why would you even put the slash there if you wanted an opening tag? HTML5 would have been a great opportunity to legalize the former behavior, and that would have broken less code. I distinctivly remember that the self-closing worked as expected even on non-void-tags in quirks mode (not XTML) in the mid 2000s, because at some point I had to fix them after new browser versions came out.