4 ms·
Both MDN and the W3C complain about Prettier putting closing slashes on HTML tags such as <input />. While allowed due to backward compatibility to XHTML, they
by assimpleaspossi 3y ago
Both MDN and the W3C complain about Prettier putting closing slashes on HTML tags such as <input />. While allowed due to backward compatibility to XHTML, they have never been specified, do nothing, and browsers ignore them so it is pointless to put them there.
https://github.com/validator/validator/wiki/Markup-%C2%BB-Void-elements https://github.com/validator/validator/wiki/Markup-%C2%BB-Vo...
https://github.com/orgs/mdn/discussions/242 https://github.com/orgs/mdn/discussions/242
- nkohari 3y agoSorry, what does this have to do with the article?
- fnord123 3y ago> While allowed due to backward compatibility to XHTML, they have never been specified, do nothing, and browsers ignore them so it is pointless to put them there. What do you mean by "never been specified"? They are in the spec: https://www.w3.org/html/wg/spec/syntax.html#start-tags https://www.w3.org/html/wg/spec/syntax.html#start-tags > 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 (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.
- assimpleaspossi 3y agoYou are looking at what I said. What you are quoting says it's allowed, and it "has no effect", but if you look at the actual element specification[1], it never says to use it. In fact, it says nothing at all about it. [1] https://html.spec.whatwg.org/dev/input.html#the-input-element https://html.spec.whatwg.org/dev/input.html#the-input-elemen... You will never find any HTML specification which will tell you a closing slash is required or that it has any meaning or does anything at all.
- alpaca128 3y agoIt very clearly says it has no effect on void elements, and then directly follows up with describing the effect it does have. And the link you provided is specifically for the input tag, which has nothing to do with the syntax definition in general. Why would they repeat a generally applicable rule in more specific sections?
- assimpleaspossi 3y agoI added some links to my original post that you need to read. That the specification for the input element--and ALL HTML elements--does not state to use a closing slash should mean something or at least indicate something. If it's required or has meaning you would think the specification would show that. It doesn't. It never has. You also need to read up on what a foreign element actually is and it's not HTML.
- HackerThemAll 3y ago[flagged]
- assimpleaspossi 3y agoYou are repeating what has already been stated and explained. Throwing insults doesn't change what's already been written.
- HackerThemAll 3y agoAnd you're still not understanding what's written there.
- ricardobeat 3y agoYour point is still unclear there. The specification allows it, for historical reasons. The fact it doesn’t recommend it does not change that. Many people, myself included, prefer to have code that is easily parseable (both mentally and by a program) without requiring a lookahead or awareness of a list of special elements. A slash for self-closing elements achieves that. It just makes sense. Can you imagine JSX allowing this?
- tobr 3y agoIt is not pointless just because browsers ignore them. It’s there for humans reading the markup.
- assimpleaspossi 3y agoNo. It's not there at all. And that's the point. No one ever told anyone to put one there.
- deleted 3y ago[deleted]
- hobofan 3y agoReact popularized it, and in its context having self-closing tags on React elements to indicate leaf nodes makes a lot of sense. Prettier just went with that and also does it for HTML. I'm wondering why you are so triggered by that issue that you have to bring it up in a context where its off-topic (it could be brought up on any post related to Prettier). The validator Wiki page even highlights that it's essentially a non-issue, except for interactions with unquoted attributes, which Prettier also converts to quoted attributes, so that interaction never happens. The other reason is for "teaching the wrong" mental model, which I guess is fair from the position of MDN, but Prettier was never designed as a "teaching formatter". And if you, even with all that context want to opt-out of that formatting, there is a community-maintained plugin that adjusts the formatting to how you want it: https://github.com/awmottaz/prettier-plugin-void-html https://github.com/awmottaz/prettier-plugin-void-html
- assimpleaspossi 3y ago> it's essentially a non-issue, except for... Hope you never get tripped up by the "except for". People were mixing XML and XHTML with HTML before React and got themselves into trouble. Why are you so triggered by someone who thinks people should just follow the standard and not write unnecessary markup/code? That is a programmer's worst nightmare but people here seem to support it.
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]