10

I need some guidance about nested lists in HTML.

I have a layout that I would like to be built like below. Is it a terrible thing to nest an element not wrapped by an <li>? I'm fairly sure that it is against standards, but don't know what ill effect it has.

<ul>
  <li>
    <h1>header 1</h1>
    <li>
       <ul>
         <li>nested</li>
         <li>list</li>
       </ul>
    </li>
  </li>
  <li>
    <h1>header 2</h1>
    <li>
       <ul>
         <li>nested</li>
         <li>list</li>
       </ul>
    </li>
  </li>
</ul>

6 Answers6

13

LI is the only element allowed as child elements of UL. Here’s a snippet of the UL element definition:

<!ELEMENT UL - - (LI)+                 -- unordered list -->

And:

Both types of lists are made up of sequences of list items defined by the LI element (whose end tag may be omitted).

Gumbo
  • 643,351
  • 109
  • 780
  • 844