0

Are end tags allowed for void elements in HTML5? Were they allowed in prior versions of HTML, what is the reasoning. Coming from a XML background, void elements are allowed end tags so was not sure.

connexo
  • 41,035
  • 12
  • 60
  • 87
  • 1
    No. E.g. for the `br` element, these are allowed: `
    ` (preferred in HTML 5), `
    ` and `
    `. If you write `
    ` the opening tag is already interpreted as the full tag, while the `` is just considered a syntax error.
    – connexo Mar 12 '21 at 00:45
  • Why does XML allow but HTML does not? @connexo – behairahmad Mar 12 '21 at 00:48
  • Because XML does not allow omitting closing a tag, which HTML does. I already explained that in my previous comment. – connexo Mar 12 '21 at 00:49
  • Not 100% a duplicate, the answers there provide an answer to this question as well. – connexo Mar 12 '21 at 00:51
  • HTML5 has an alternative, [XML compliant syntax](https://html.spec.whatwg.org/multipage/xhtml.html#the-xhtml-syntax), in which closing tags are allowed for void elements. You access it by serving the page with the `application/xhtml+xml` content type. – Alohci Mar 12 '21 at 01:20

1 Answers1

1

The reasoning behind start and end tags are to determine where an element starts and ends, so no they are not allowed since they have no content.

And this is from the spec page.

Void elements only have a start tag; end tags must not be specified for void elements.

W3.org

HMZ
  • 1,931
  • 1
  • 12
  • 20