[whatwg] self-closing tags in html5

William F Hammond hammond at csc.albany.edu
Fri Dec 31 10:59:33 PST 2010


Ian Hickson <ian at hixie.ch> writes:

> On Sat, 25 Sep 2010, William F Hammond wrote:
>>
>> In the spec at 8.1.2.1 (6) (for the text/html serialization):

The section number refers to the W3C version at
http://www.w3.org/TR/html5/

>>    Then, if the element is one of the void elements, or if the
>>    element is a foreign element, then there may be a single U+002F
>>    SOLIDUS character (/).  This character has no effect on void
>>    elements, but on foreign elements it marks the start tag as
>>    self-closing.
>> 
>> It would be better to allow self-closing tags on all de facto empty
>> elements, foreign or not and defined-empty or not.
>
> In 
> http://lists.w3.org/Archives/Public/public-html-comments/2010Sep/0027.html 
> you further clarify "de facto empty" as meaning:
> | A defacto empty element is an element that is either defined-empty in
> | the document type definition OR any element in the current document
> | instance that has no content.
>
> While syntactic sugar to make "<foo/>" equivalent to "<foo></foo>" even 
> for elements that are not void elements would probably be quite popular, 
> it is unfortunately incompatible with legacy content. It turns out that 
> there is a large amount of content that includes "/" characters in 
> positions that appear to be the end of the start tag but that do not 
> intend to have the browser close the element immediately.
>
> For example, markup such as the following is sadly common:
>
>    <p/>Hello world!</p>

My comment about cognitive dissonance in
http://lists.w3.org/Archives/Public/public-html-comments/2010Sep/0026.html
is also relevant here.

The parsing rules of section 8.2 (W3C version) in the html5 spec do
adequately separate the cases.

So as I read those rules (on September 25):

1. your example above would be parsed as a non-empty paragraph

2. <a href=http://example.foo/>an example</a>

   would be parsed with the '/' as part of the url

3. <a id="mylabel"/>  OR  <a id=mylabel />

   would be understood as self-closing under section 8.2 but then
   handled as regular open tags.  That is cognitive dissonance.  Then
   because <a> has transparent content, the nonsense can be propogated
   through several paragraphs.

Why not re-write 8.1.2.1 (6) as follows:

Then there may be a single U+002F SOLIDUS character (/).  This
character has no effect on void elements.  On foreign elements it
marks the start tag as self-closing.  On non-void HTML elements it
marks the start tag as self closing if it is immediately preceded by
whitespace or by a single instance of one of the two markup quoting
characters U+0022 or U+0027; otherwise it has no effect, and the
start tag is not understood as self-closing.

Without language of this type the specification has not actually
covered the example you cited, i.e.,

             <p/>Hello world!</p>  ,

where the <p/> should not be self-closing

                                    -- Bill





More information about the whatwg mailing list