[whatwg] self-closing tags in html5

Kornel Lesiński kornel at geekhood.net
Fri Dec 31 08:33:40 PST 2010


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.

-- 
regards, Kornel Lesiński



More information about the whatwg mailing list