Re:Using Standard HTML (1997)
by firefoxd on Sunday January 19, 2020 @02:34PM
(#22093431)
Yes you can.
And it is valid XML. They are referred to as self closing tags.
[ Parent
| on HN ]
It is valid XML. It means totally different thing in HTML.
The self-closing form is fine in HTML5 for those examples, since they are void elements. The "/" gets ignored, which is what you want in that case.
It fails if you try this with non-void elements: E.g. XHTML <div /> might turn into <div> in HTML5, which opens a div element, which is not the same. (I'm not sure if this behaviour is specified or not)
https://html.spec.whatwg.org/multipage/syntax.html#start-tag...
> 6. Then, if the element is one of the void elements [...] then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements [...]
https://html.spec.whatwg.org/multipage/syntax.html#void-elem...
> area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr