5 ms·
Img and br are not allowed to be closed.
by recursive 9mo ago
Img and br are not allowed to be closed.
- swiftcoder 9mo agoWorse, due to the aforementioned permissive error handling in HTML parsers, a closing </br> tag will end up inserting a second line break
- imiric 9mo agoWrong.[1] > 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 (/) If you're going to be pedantic, at least be correct about it. [1]: https://html.spec.whatwg.org/multipage/syntax.html#start-tags https://html.spec.whatwg.org/multipage/syntax.html#start-tag...
- swiftcoder 9mo agoThere can't however be a separate closing tag, which is a reasonable interpretation of the post you are replying to
- recursive 9mo agoAlso the slash in <br /> explicitly has no effect, per specification.
- eddyg 9mo agoYou left out the rest of the spec: > 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. (The void elements are listed here: https://developer.mozilla.org/en-US/docs/Glossary/Void_element https://developer.mozilla.org/en-US/docs/Glossary/Void_eleme... )
- imiric 9mo agoAll of that is a far cry from elements not being allowed to be closed. Please point to where the spec mentions that. MDN is not the spec.
- recursive 9mo agoIt's the next sentence. > On void elements, it does not mark the start tag as self-closing but instead is unnecessary and has no effect of any kind. https://html.spec.whatwg.org/multipage/syntax.html#start-tags https://html.spec.whatwg.org/multipage/syntax.html#start-tag...
- hnlmorg 9mo agoYou close them in the same tag: <br/>
- pornel 9mo agoThis syntax is ignored in HTML. The / is thrown away and has no effect. This non-closing talisman means that <div/> or <script/> are not closed, and will mess up nesting of elements.
- hnlmorg 9mo agoIn HTML, yes. But I thought the OP was talking about XHTML?
- recursive 9mo agoNo. In XHTML, you are required to close your p and li tags. In HTML, the "self-closing" tag is meaningless. That slash doesn't do anything. You can't self-close a <script> or <div> tag. It only appears to work for tags that are don't allow closing.
- hnlmorg 9mo agoWe aren’t talking about p and li tags which require data to be embedded. We are talking about self-contained tags such as br. In XHTML (and XML in general) tags absolutely can be open and closed inside the same tag via the method I described: <br/> Look it up if you don’t believe me. But this is correct.
- recursive 9mo agoAre we talking about HTML or XHTML? In HTML, you can add the slash, but it has no effect. The spec explicitly says that the slash does not close the element. The fact that it's "br" does. So you are allowed to add that slash. But adding it does not close the element. > On void elements, it does not mark the start tag as self-closing but instead is unnecessary and has no effect of any kind. https://html.spec.whatwg.org/multipage/syntax.html#start-tags https://html.spec.whatwg.org/multipage/syntax.html#start-tag... In XHTML, normal XML rules apply, as you say. That's consistent with what I've said earlier in this thread also.