One of those “Hey, Wait a Minute” Moments

I think I’m pretty good with HTML. So when I discover that I’m wrong about something, I’m pretty taken aback. In my defense, I don’t think I’m alone in being wrong.

Take a look at this page about HTML lists. It’s a nice, pretty page. Its makers clearly know what they’re doing. But notice what it has to say about nested lists. They say that you can nest lists. Like so:

<ul>
  <li>Item 1</li>
  <ul>
    <li>Sub-item 1</li>
  </ul>
  <li>Item 2</li>
</ul>

I’ve been writing HTML code like that ever since I was a child programmer back in 1996. Turns out, it’s not legal HTML, according to the 4.01 spec. The only sub-element to a list is the list item element. You can’t put an unordered list inside another unordered list.

This is legal:

<ul>
  <li>Item 1
    <ul>
      <li>Sub-item 1</li>
    </ul>
  </li>
  <li>Item 2</li>
</ul>

In this case, the nested list is, itself, contained in the first list item.

It's only fair to share...
Share on Facebook
Facebook
Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Leave a Reply