What are all the valid self-closing elements (e.g. <br/>) in XHTML (as implemented by the major browsers)?
I know that XHTML technically allows any element to be self-closed, but I’m looking for a list of those elements supported by all major browsers. See http://dusan.fora.si/blog/self-closing-tags for examples of some problems caused by self-closing elements such as <div />.
Every browser that supports XHTML (Firefox, Opera, Safari, IE9) supports self-closing syntax on every element.
<div/>,<script/>,<br></br>all should work just fine. If they don’t, then you have HTML with inappropriately added XHTML DOCTYPE.DOCTYPE does not change how document is interpreted. Only MIME type does.
W3C decision about ignoring DOCTYPE:
It’s a very common pitfall, because W3C Validator largely ignores that rule, but browsers follow it religiously. Read Understanding HTML, XML and XHTML from WebKit blog:
To test whether you have real XHTML or invalid HTML with XHTML’s DOCTYPE, put this in your document:
It validates, and in real XHTML it works perfectly (see: 1 vs 2). If you can’t believe your eyes (or don’t know how to set MIME types), open your page via XHTML proxy.
Another way to check is view source in Firefox. It will highlight slashes in red when they’re invalid.
In HTML5/XHTML5 this hasn’t changed, and the distinction is even clearer, because you don’t even have additional
DOCTYPE.Content-Typeis the king.For the record, the XHTML spec allows any element to be self-closing by making XHTML an XML application: [emphasis mine]
It’s also explicitly shown in the XHTML spec: