30

Elements I've defined (that don't require contents) seem to work just fine without a closing tag. I'm wondering if it's just a quirk of the browser though.

What's the verdict? Is it theoretically possible? What if the parser sees the element before its definition?

A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128
  • Can you give an example of the element? And details of the browser you're using if you think it's relevant? – Jamie Bull May 30 '14 at 18:51
  • Regarding that "theoretically": empty elements with a self-closing open tag (like `

    `) should definitely be possible. In practice, though, from what I've read (e.g. on SO), browsers have mostly just been ignoring self-closing open tags, unfortunately.
    – Sz. Sep 10 '19 at 23:58
  • Related: https://github.com/w3c/webcomponents/issues/624. – Константин Ван Dec 08 '19 at 02:06

1 Answers1

43

Yes. Custom elements require a closing tag. Only certain tags in HTML are allowed to be self-closing due to the parser.

The following is a complete list of the void elements in HTML:

area, base, br, col, command, embed, hr, img, input, keygen, link, meta, param, source, track, wbr

and :

A non-void element must have an end tag, unless the subsection for that element in the HTML elements section of this reference indicates that its end tag can be omitted.

http://www.w3.org/TR/html-markup/syntax.html#syntax-elements

Community
  • 1
  • 1
ebidel
  • 23,921
  • 3
  • 63
  • 76
  • 8
    Expanding on this, when I've left off closing tags the parser has inserted them fairly late. So ` ` was interpreted as ` ` which can lead to some unexpected results. – Peter Burns May 30 '14 at 20:42
  • I found this to block `document.querySelector`...any elements after the self-closing web-component element aren't selectable. – chovy Nov 11 '21 at 03:48