[whatwg] self-closing tags in html5

[Originally mailed to whatwg on Sat, 25 Sep 2010 22:24:49 -0400,
 but blocked from the list due to subscription troubles]

In the spec at 8.1.2.1 (6) (for the text/html serialization):

   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.  That is: for any
tag name "foo", the markup "<foo/>" should be equivalent to
"<foo></foo>".  If "foo" is a defined-empty element in the html
name space, then all of "<foo>", "<foo/>", and "<foo></foo>" should
be equivalent.

This is better because (1) authors are given more choice and (2) DOM
building is simplified.

For example, while it is true that major browsers seem to treat "<p/>"
as an open tag, the relevant question for backward comptatibility is
whether anyone has been relying on the idea that "<p/>" can be used to
begin a non-empty paragraph.

                                    -- Bill

----------------------------------------------------------------------
William F. Hammond                   Dept. of Mathematics & Statistics
hammond at albany.edu                            The University at Albany
http://www.albany.edu/~hammond/                    Albany, NY (U.S.A.)
----------------------------------------------------------------------

P.S.  It is true that the W3C HTML 4 & 4.01 specifications formally
(and unwisely for text/html) enabled full SHORTTAG in the accompanying
SGML declaration.  So, for example,

     <p/Hello guys!  This is text in
        a formally legal paragraph. /

is a correctly marked HTML-4 "p" element according to the
specification.  But there was no significant appearance of this markup
across the web in text/html.  (It is simple to modify the SGML
declaration for HTML 4 to disable this usage.)  A spec compliant
implementation of HTML 4 would, however, render the content of

     <p/>Hello guys!</p>

as ">Hello guys!".

Received on Sunday, 26 September 2010 13:12:16 UTC