The W3C validator (Wikipedia) doesn’t like self-closing tags (those that end with “/>”) on non-void elements. (Void elements are those that may not ever contain any content.) Are they still valid in HTML5?
Some examples of accepted void elements:
<br />
<img src="" />
<input type="text" name="username" />
Some examples of rejected non-void elements:
<div id="myDiv" />
<span id="mySpan" />
<textarea id="someTextMessage" />
Note:
The W3C validator actually accepts void self-closing tags: the author originally had a problem because of a simple typo (\> instead of />); however, self-closing tags are not 100% valid in HTML5 in general, and the answers elaborate on the issue of self-closing tags across various HTML flavors.
(Theoretically) in HTML 4,
<foo /(yes, with no>at all) means<foo>(which leads to<br />meaning<br>>(i.e.<br>>) and<title/hello/meaning<title>hello</title>). I use the term "theoretically" because this is an SGML rule that browsers did a very poor job of supporting. There was so little support (I only ever saw it work in emacs-w3m) that the spec advises authors to avoid the syntax.In XHTML,
<foo />means<foo></foo>. This is an XML rule that applies to all XML documents. That said, XHTML is often served astext/htmlwhich (historically at least) gets processed by browsers using a different parser than documents served asapplication/xhtml+xml. The W3C provides compatibility guidelines to follow for XHTML astext/html. (Essentially: Only use self-closing tag syntax when the element is defined as EMPTY (and the end tag was forbidden in the HTML spec)).In HTML5, the meaning of
<foo />depends on the type of element: