Hacker News new | past | comments | ask | show | jobs | submit login

> un-learning `<br />`

wait what ?




`<br />` was the correct way in XHTML to do HTML5's `<br>`

(I think `<br />` still works in HTML5 or maybe browsers just don't mind it, but it's not the recommended way.)


Having an unclosed tag somehow seems wrong. What was the reasoning behind this?


Because HTML5 is not actually a subset of XML. Every element in XML must be closed, but in HTML5 certain tags (like <hr>, <img>, or <br>) are defined as "void" which means they have no nested content and therefore it's technically improper to close them (although I'd be shocked if any major browsers actually care about that). In other words, an <img> tag does not "open" the definition of a new section of the document the way <div> or <span> do, and it makes no sense to "close" something that was never "open" to begin with.


That's an arbitrary style choice in the spec. Saying "it's void so never use / " is no more natural than saying "it's void so always use /".

Arguably, it's bad style to use the same syntax for opening a tag as for a void tag, because it forces semantics into the syntax for trivial benefit. With out the "/", your HTML syntax parser now has to include a lexicon of all the void tags, and be updated with spec revisions.


Perhaps they made it implicitly self-closing.


thanks i never got the news, i hope browsers dont hate me


Haha I've known for years and I still use <br />. Usually the linter will nag me, but otherwise I just don't care enough to fix it.


i think the feeling of closure i get with the /> is addictive




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: