[whatwg] Empty elements

28.8.2011 3:10, Nils Dagsson Moskopp wrote:

> Bronislav Klu?ka <Bronislav.Klucka at bauglir.com>  schrieb am Sun, 28 Aug
> 2011 01:56:15 +0200:
>
>> HTML5 defines several void elements.
>> I think this enumeration is insufficient, and I'd like to suggest to
>> simply allow every element to have syntax with />  at the end if such
>> element has no content.
>
> This would most certainly not be backwards-compatible.

Indeed. The validator validator.nu (and its close in the W3C Markup 
Validator) reflects common browser behavior when it reacts to e.g. <p/> 
as follows:

Error: Self-closing syntax (/>) used on a non-void HTML element. 
Ignoring the slash and treating as a start tag.

So allowing e.g. <script src=foo /> would mean that existing browsers 
would treat subsequent data, up to the end of data or the first 
occurrence of </script>, whichever occurs first, as a script.

The word "void", though used even in the validator's message, is at 
least misleading if not incorrect. The correct word is "empty".

The interesting question is: Where do the normative rules say that 
self-closing syntax must not be used for other than empty elements?

The XHTML serialization rules say, at
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-xhtml-syntax.html#the-xhtml-syntax
as follows:

"The syntax for using HTML with XML, whether in XHTML documents or 
embedded in other XML documents, is defined in the XML and Namespaces in 
XML specifications. [XML] [XMLNS]

This specification does not define any syntax-level requirements beyond 
those defined for XML proper.

The XML spec says, at
http://www.w3.org/TR/xml/#sec-starttags
as follows:
"For interoperability, the empty-element tag SHOULD be used, and SHOULD 
only be used, for elements which are declared EMPTY."
So it is just a SHOULD, not MUST. Besides, there is no concept of being 
declared EMPTY in HTML5, as no DTD is provided.

> Have you tried using the XML serialization instead?

How would things be different in XML serialization? The whole idea of 
"self-closing" tags is an XML idea, and it would be rather pointless to 
use them in HTML serialization at all - there it is much more natural to 
write <br> and not <br/> or <br />.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

Received on Saturday, 27 August 2011 21:26:26 UTC