Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Self-closing tags would make more sense here, i.e.

   <v $foo />


I found some references here:

"Custom elements cannot be self-closing because HTML only allows a few elements to be self-closing"

https://developers.google.com/web/fundamentals/web-component...

It seems only void elements are allowed to be self closing:

https://html.spec.whatwg.org/multipage/syntax.html#void-elem...

The trailing U+002F (/) in a start tag name can be used only in foreign content to specify self-closing tags. (Self-closing tags don't exist in HTML.) It is also allowed for void elements, but doesn't have any effect in this case.

https://html.spec.whatwg.org/multipage/parsing.html#parse-er...


The important bit here being that the custom element API simply doesn't allow declaring all relevant features of elements except their names.

Whereas (SGML) DTDs such as in any DTD for HTML before HTML5, elements were declared like this

    <!element img - - EMPTY>
for elements with declared content EMPTY ("void elements" in HTML5 parlance), and

    <!element html O O
     (head,body)>
as a basic example for tag omission/inference, where given these tag omission indicators (the letter O in the respective position), you can omit the html tags (and also head, and many other start- and end-element tags) when SGML can unambiguously infer those for you.


Valid custom elements must also contain a dash.


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


it seems the DOMParser doesn't allow custom self closing tags, I tried and it didn't work




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

Search: