by codedokode · 2y ago · 0 comments
<div/>
And it will be interpreted as <div>, not as a pair of <div></div>.HTML just ignores the slash character, it doesn't support XML-style self-closing tags. HTML is not XML.
Self-closing tags with the trailing slash are absolutely supported by HTML5, in some circumstances.
Quoting the spec [1]:
> Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/), which on foreign elements marks the start tag as self-closing. On void elements, it does not mark the start tag as self-closing but instead is unnecessary and has no effect of any kind. For such void elements, it should be used only with caution — especially since, if directly preceded by an unquoted attribute value, it becomes part of the attribute value rather than being discarded by the parser.