[whatwg] self-closing tags in html5

Ian Hickson ian at hixie.ch
Mon May 2 15:47:06 PDT 2011

On Fri, 31 Dec 2010, Kornel LesiÅ~Dski wrote:
> On Fri, 31 Dec 2010 07:18:52 -0000, Ian Hickson <ian at hixie.ch> wrote:
> > 
> > For example, markup such as the following is sadly common:
> > 
> >   <p/>Hello world!</p>
> > 
> > I have therefore not changed the spec in response to this request.
> I've checked www.dotnetdotcom.org dataset looking for 
> <tag…/>…</tag>, excluding <script> and comments.
> You're right about HTML elements — constructs such as <br/></br>, <a 
> href=/></a> and <div/></div> are common (7% of pages have at least one 
> such construct!), and almost every HTML element is misused like this 
> (even <body/>, <style/>, <b/>).
> However, for non-HTML elements the story is completely different.
> There are very few pages (< 0.01%) that have this error on non-HTML elements.
> I've found few cases of <personname productid="常凸显" w:st="on"
> />常凸显</personname /> and <Actinic:COOKIECHECK/></Actinic:COOKIECHECK/>,
> which don't seem to be used on client-side anyway.
> Parsing of non-HTML elements is not interoperable between IE and non-IE 
> browsers. IE already supports self-closing syntax on prefixed elements, 
> but other browsers don't:
> http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%3Cbody%3E%0D%0A%3Cfoo%3Abar%2F%3Eaa%0D%0A%3Cfoo%3Abar%3Ebb%3C%2Ffoo%3Abar%3E
> and IE cannot properly parse unknown non-prefixed elements, except when 
> (relatively new) workaround is used (http://ejohn.org/blog/html5-shiv):
> http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%3Cbody%3E%0D%0A%3Cfoobar%2F%3Eaa%0D%0A%3Cfoobar%3Ebb%3C%2Ffoobar%3E
> With such interoperability problems, I think it's unlikely that there 
> are many pages that rely on particular parsing of non-HTML elements, 
> especially one that disagrees with XML.
> I think HTML5 can specify that a fixed set of old HTML elements has to 
> be closed according to HTML rules, but all other elements support 
> self-closing syntax like XML.

On Fri, 31 Dec 2010, Aryeh Gregor wrote:
> That just makes the HTML syntax even more complicated and confusing. At 
> least at present it's consistent in this respect (although not in many 
> other respects).

I'm kinda with Aryeh on this. I don't really see much value in adding yet 
another special case here. Consider how this will be in 30 years, once 
we've added another dozen elements: "Yes, <foo/> is a closed element. No, 
you can't do that with <p/>. Or <ul/>. You can do it with <bar/>, sure."

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

More information about the whatwg mailing list