4 ms·
Unfortunately, the XML-style syntax with all tags closed isn't allowed in HTML for certain tags. For instance, you can't close <input> or <br> or <hr> tags.
by JoshTriplett 7y ago
Unfortunately, the XML-style syntax with all tags closed isn't allowed in HTML for certain tags. For instance, you can't close <input> or <br> or <hr> tags.
- firefoxd 7y agoYes you can. <input />, <br />, and <hr /> And it is valid XML. They are referred to as self closing tags.
- rimliu 7y agoIt is valid XML. It means totally different thing in HTML.
- detaro 7y agoThe 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-tags 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-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