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

HTML doesn't have self-closing tags.

To down voters: No seriously, it doesn't. XHTML has self-closing tags but HTML does not. It will happily ignore your self-closing tags if you have them but it accomplishes nothing. Self closing tags lived and died with XHTML.




It does. From the HTML5 specification:

> 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.

https://html.spec.whatwg.org/multipage/syntax.html#start-tag...

> It will happily ignore your self-closing tags if you have them but it accomplishes nothing.

Sure. They are optional for HTML elements. That’s not the same thing as “HTML doesn’t have them”. HTML has them, understands them, and chooses to only do something with them for foreign elements.

The problem with using it in this situation is not that HTML doesn’t have self-closing tags, it’s that custom elements cannot be void elements.


Foreign elements are elements from XML namespaces so obviously XML rules apply.

> That’s not the same thing as “HTML doesn’t have them”.

HTML has always ignored them. They have no affect on any HTML element. If you attempt to use them as in XML, on normal elements, they do not close that element. If you use them on void elements, they obviously also do nothing. It's utterly meaningless in HTML.


> HTML has always ignored them.

No, browsers have always ignored them.

Until HTML5 came along, they were the start of a NET. It was incorrect syntax that would probably end up causing a parse error later in the document thus mangling it. However because browsers didn't fully comply with SGML-based HTML parsing, the mangling didn’t happen and the result was that this syntax mistake would have no effect. Two bugs cancelling each other out.

That is a different situation to HTML5, which explicitly states that it’s an acceptable no-op.

“This is okay, but you don’t need to do anything with it” is a different situation to “This is a NET” followed by “I don’t know what a NET is, so I’m going to mis-parse it as an attribute and then ignore it because it makes no sense as an attribute”.




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

Search: