Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the reason behind not allowing self-closing tag in custom element in spec?

<self-closing /> tag are not allowed in HTML custom element.

Why is that?

Many cases just need void tag, I guess by that, code would be more readable. On the other hand, it implies semantic meaning more directly.

Just like <hr />, which by code itself means there shouldn't be any children inside it, because there's no place for that. Plus it has nothing to do with children.

Custom elements cannot be self-closing because HTML only allows a few elements to be self-closing. (read more)

like image 977
Mehdi Raash Avatar asked Jul 31 '17 14:07

Mehdi Raash


1 Answers

The browser has to special case void elements so it knows to close them immediately without looking for an end tag.

No custom element will be in a browser's internal list of void elements.

Remember, the significant thing that indicates an element is void is the tag name. The optional / is just syntactic sugar for people and syntax highlighters that are still trying to think in terms of XML. It's meaningless to an HTML parser.

like image 54
Quentin Avatar answered Oct 11 '22 01:10

Quentin