Comment by jraph
7 hours ago
Let's just say that I don't think the truths you are pushing are as absolute as you seem to think, and I think they are a reflect of how you view the world more than anything.
And that by correcting people that mention HTML5, you will probably just annoy people without achieving anything worth it. That would be true even if you are absolutely correct.
It's peak "well, actually", with the twist it might not even actually be.
That's not the truth, just my opinion, and I appreciate that you might not agree.
Note that OP didn't mention "The HTML5 Standard", they mentioned "HTML5".
I would rather be correct and annoy people than be wrong. It's fascinating to me today to see so many people allow "good enough" over correctness. It's a disaster waiting to happen.
For example, people get annoyed when I tell them not to put closing slashes on void HTML elements. They reply that it doesn't matter because it's in the standard that it's allowed so it's perfect HTML. What they don't bother to understand, despite my pointing to online documentation, is that placing closing slashes on some elements can cause harm and that no HTML standard tells you to put one there or has ever required it. Yet they argue with me anyway. Much like you argue with me about this. And that's when I stop.
At this point, closing slashes for void elements is coding style, exactly like white space we use for indentation. You can't be right because this is in opinion territory. Exactly like whether one should put semicolons or not in JavaScript when you have automatic semicolon insertion. Some people have strong opinions on the matter. Putting them has drawbacks, and not putting them too, and in both cases, readability and clarity, which is subjective, is a factor.
You are right that it has drawbacks and that it can bite. OTOH, people using closing slashes usually also quote all their attributes and will virtually never be bitten by this.
But people have backgrounds and habits, there's culture around a language like HTML, and these backgrounds are cultures have been shaped by XHTML.
Whether to put or not to put the slash is a healthy conversation to have and there are valid points for both, but if you are arguing like you are doing here for HTML5, considering "they don't bother to understand", you'll lose your arguments and people will find you annoying.
Some people feel bad about not closing br with a slash because it kinda feels like unmatched parentheses, or old malformed HTML from the 90's. That's not reasonable, but for the better or the worse, you can't just ignore this.
Some people sometimes write XML, and when they switch to HTML, their XML habits are there, and following habits especially when they are mostly harmless is efficient.
Some people write polyglot (X)HTML for some reason, and there the slash is needed.
There are reasons to put the slash, like there are reasons not to write it, and you can't just impose your truths like this.
Can you share some of the links you'd share?
I'm someone who still lives in the XHTML world and pedantically close all of my elements. Seems like I need a knowledge refresher.
(and by the way, I could Google this, or any other chatbots, but I want to hear from your experience).
Reasons for not putting the slash in HTML:
- since the slash doesn't have any meaning in HTML, if you don't quote your attributes, you are at risk that your slash is attached to the value or your unquoted attribute: <br class=myclass/> ← uh oh, class = "myclass/"!
You can test this by visiting the following URL, and inspecting the content: data:text/html,<br class=myclass/>
Now guess what happens to the unquoted src attribute of the img tag followed by an unspaced stray slash… OTOH, you don't need to not quote the src attribute…
- it can give a false sense of correctness, one can reasonably consider that the closing effect of the slash is pure illusion and even potentially confusing.
For backward compatibility, a stray slash at the end of the start tag is ignored, not considered as an attribute that doesn't have a value, so there's argument to be made that it's still part of the syntax. You'll never have any issue if you always put a space before the slash (which most people who put the slashes do because of a silly bug in a browser that has not been relevant for a long time), or if you quote all your attributes.
I don't understand why they haven't decided to make the HTML5 parser parse <br class=myclass/> like <br class=myclass> but I guess it is what it is.
https://github.com/validator/validator/wiki/Markup-%C2%BB-Vo...
https://github.com/validator/validator/wiki/Markup-%C2%BB-Vo...
https://www.matsimon.dev/blog/to-close-or-not-to-close
https://github.com/w3c/html/issues/737
There's more.