html: creating nested lists using valid xhtml code
A nested list is essentially a sub-list, and can be very helpful when clarifying points in an unordered list. Unfortunately, many editors and programs do not properly format these lists in valid XHTML Strict code, resulting in needless errors. This first came to our attention when testing out a WYSIWYG editor without proper XHTML Strict support.
Here is an example of a simple unordered list with a nested element.
- A Point About Something
- This bullet is making a point about something
- And these bullets explain the main point
- Heres Another Main Point
- And Another
Now, the problem we’ve found is that some editors do not properly carry the <li> tag below the nested list. This is required for XHTML Strict validation, and as long as your editor does not automatically “correct” this, you should be able to fix this error in only a minute or two.
Here’s the incorrect code:
<ul>
<li>A Point About Something</li>
<ul>
<li>This bullet is making a point about something</li>
<li>And these bullets explain the main point</li>
</ul>
<li>Heres Another Main Point</li>
<li>And Another</li>
</ul>
Depending on how long your list is, this will give you a boatload of unnecessary errors, including “document type does not allow element “ul” here; assuming missing “li” start-tag,” and “end tag for “li” omitted, but OMITTAG NO was specified.”
To fix this, all we’ll need to do is move that red highlighted </li> tag below the nested list, after the </ul> tag. We’ve now changed the color of that tag to blue to show you where it gets placed.
Here’s the correct code:
<ul>
<li>A Point About Something
<ul>
<li>This bullet is making a point about something</li>
<li>And these bullets explain the main point</li>
</ul></li>
<li>Heres Another Main Point</li>
<li>And Another</li>
</ul>
Compatibility:
This method has been tested in and is compatible with Internet Explorer 5.5, 6, 7, Firefox (PC and Mac), Netscape and Safari (PC and Mac).
That’s all folks!
Thank you for taking the time to read one of our articles. If you still find yourself stuck, we’d be happy to lend a hand. Simply leave us a comment below, and we’ll do our best to help you out. Found something that we’ve missed? We’d love to hear it.
Tags: html, nested lists, xhtml strict






June 22nd, 2008 at 9:56 pm
I am still having trouble with these tags. I made the changes you suggested and my tags still do not validate.
Can you help….?
June 22nd, 2008 at 9:58 pm
Hi Sandra,
We’d be happy to help, do you have a link to the page that you are having trouble with?
February 3rd, 2009 at 3:14 pm
Boy do I wish I’d found you a few frustrating days ago! I’ve been running test after test in the W3.org xHtml validation and could not for the life of me figure this out.
The hardest part of finding information is having the right search terms. Finally found you in the top results with “valid list nesting +xhtml” in Google. I found very nice online reference guides for what’s right as a nested tag, and valid child or parent tags, but finding this little twist was a doozy!
Thanks a heap for the info. Now my sub-menu list markup works, looks great AND passes validation! Woo HOo!
June 23rd, 2009 at 6:56 am
Thanks for your kind words, and we were happy to help Pierre! Be sure to come back to us if you get stuck anywhere else along the way.