3 ms·
The author has a point, but I object to this mischaracterization: > XHTML, being based on XML as opposed to SGML, is notorious for being author-unfriendly due
by imiric 9mo ago
The author has a point, but I object to this mischaracterization:
> XHTML, being based on XML as opposed to SGML, is notorious for being author-unfriendly due to its strictness
This strictness is a moot point. Most editors will autocomplete the closing tag for you, so it's hardly "unfriendly". Besides, if anything, closing tags are reader-friendly (which includes the author), since they make it clear when an element ends. In languages that don't have this, authors often add a comment like `// end of ...` to clarify this. The article author even acknowledges this in some of their examples ("explicit end tags added for clarity").
But there were other potential benefits of XHTML that never came to pass. A strict markup language would make documents easier to parse, and we wouldn't have ended up with the insanity of parsing modern HTML, which became standardized. This, in turn, would have made it easier to expand the language, and integrate different processors into the pipeline. Technologies like XSLT would have been adopted and improved, and perhaps we would have already had proper HTML modules, instead of the half-baked Web Components we have today. All because browser authors were reluctant to force website authors to fix their broken markup. It was a terrible tradeoff, if you ask me.
So, sure, feel free to not close HTML tags if you prefer not to, and to "educate" everyone that they shouldn't either. Just keep it away from any codebases I maintain, thank you very much.
To be fair, I don't mind not closing empty elements, such as `<img>` or `<br>`. But not closing `<p>` or `<div>` is hostile behavior, for no actual gain.
- recursive 9mo agoImg 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.
- Finnucane 9mo agoFor ebook production, you need to use xhtml, the epub standard is defined that way. And it is indeed useful to be able to treat them as xml files and use xslt and xquery, etc. with them.