user3342816
user3342816

Reputation: 1263

Descendants and content model in HTML specification

Let us say we have this markup:

<ul>
    <li>
        <span></span>
    </li>
</ul>

Reading the specifications for ul we have:

Content model:
         Zero or more li and script-supporting elements.

And the semantics section for Content model say, (emphasize mine):

Content model
           A normative description of what content must be included as
           children and descendants of the element.

I am surely thinking of this wrong, but I can not get the two to compute. As a span is not part of "Zero or more li elements" and it is a descendant of the ul.

If the spec said: "A normative description of what content must be included as children of the element." I would get it, but that might crash with other parts of the specification.

My question is how to interpret this.


To add some more context. An ul can only have li as children. But from the above, if one forget everything one know about HTML etc., I would have interpret that as one of two:

By "zero or more" the latter stands stronger.

Upvotes: 4

Views: 138

Answers (1)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201588

The quoted description, from 3.2.3 Element definitions, is rather loose and even misleading. The next part, 3.2.4 Content models, describes what the content model really is: “Each element defined in this specification has a content model: a description of the element's expected contents. An HTML element must have contents that match the requirements described in the element's content model. The contents of an element are its children in the DOM, except for template elements, where the children are those in the template contents”.

Thus, the content model specifies both the allowed and the required content (though not all elements have required content), in terms of children, which means child nodes. This includes, as applicable, element childen and text node children (e.g., some elements have only text allowed as content).

This means that an a ul element may only have li and script elements as children. The li elements have content models of their own, which are rather permissive. There is no required content; even <ul></ul> is allowed in HTML5.

Upvotes: 3

Related Questions