The self-closing element tag syntax (/>
) was introduced to allow HTML to exist as an XML dialect as XHTML. It is not necessary in SGML (HTML and XML's superset) as the DTD declares what elements are self-closing or not.
In SGML, the trailing /
character is interpreted as a flag attribute with the literal name /
and is otherwise ignored, making it a polyglot syntax.
In the current HTML5 syntax revision there is an explanation:
A Self-closing tag is a special form of start tag with a slash immediately before the closing right angle bracket. These indicate that the element is to be closed immediately, and has no content. Where this syntax is permitted and used, the end tag must be omitted. In HTML, the use of this syntax is restricted to void elements and foreign elements. If it is used for other elements, it is treated as a start tag. In XHTML, it is possible for any element to use this syntax. But note that it is only conforming for elements with content models that permit them to be empty.