(The XML serialisation is still a thing, in various contexts. Serve a document with an XHTML MIME type and the XML parser will be used; or embed HTML in SVG via foreignObject and it’ll be XML serialisation you need. Also note that SVG in HTML invokes… uhh… more XMLy behaviour from the HTML parser, so that the trailing slash does have its XML meaning.)
Some tags such as <meta> and <img> are always considered as a leaf node ("void element"). The HTML parser knows that these tags cannot contain other tags.
Other tags, such as <p> or <li> have various rules saying how to automatically insert a closing tag if it's missing. For example, if you leave out the </li> tags in a list the HTML parser will parse it as if you had closed all the list items.
<ul>
<li>first
</li>second
</ul>
<ul>
<li>first</li>
</li>second</li>
</ul>
For these tags, what ends up happening if you try to use the XML self-closing notation is that the "/>" is ignored and then the missing close tag is inserted at a later point, which may or may not be where you want.If you have something like this:
<div>
<h1>A
<p>B
<img>
<p>C
<h2>D
<p>E
</div>
… it’ll parse to this: <div>
<h1>A
<p>B
<img>
</p><p>C
</p></h1><h2>D
<p>E
</p></h2></div>
See, the headings did get closed eventually, even without their proper closing tags; it just wasn’t where you wanted, either time. (The paragraphs, on the other hand, probably ended where you expected.)Of your example, I think you typed it incorrectly in a couple of places. Here’s what I think you meant to express (plus a third one to make things clearer with the second having a bad trailing slash):
<ul>
<li>first
<li/>second
<li>third
</ul>
… and here’s what that is precisely equivalent to: <ul>
<li>first
</li><li>second
</li><li>third
</li></ul>Not sure why the the self closing tags became widely used
Source? https://caniuse.com/xhtml says otherwise
> You couldn't do stuff like <div/> and get away with it.
I just tried on both Firefox and Chromium, they parse it properly.
I don't see a reason to mix html and xhtml today. It will only lead to problems. (I.e using self-closing tags and & mismatches in urls)
If you use <div/> in html the browser will just ignore the end / See https://jsfiddle.net/sw8j9fo2/
For a while adhering to the open/close conventions helped use tooling / libraries built around the assumptions for XML in dealing with HTML, maybe up through the late 00s/early 10s.
Any utility gains there faded as HTML5 conventions and libraries became more solid, but I still have a bit of the habit, especially with <img/> & <br/>.
https://www.w3.org/TR/2011/WD-html-markup-20110113/syntax.ht...
I was coincidentally checking the same thing yesterday, and yes, '/>' is optional.