Visit DynamiX Web Design! E-Mail DynamiX Web Design!

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: , ,

Pass This Article On! Tiny Url: http://tinyurl.com/c32wry

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

4 Responses to “html: creating nested lists using valid xhtml code”

  1. Sandra WyattNo Gravatar Says:

    I am still having trouble with these tags. I made the changes you suggested and my tags still do not validate.
    Can you help….?

  2. DynamiXLabsNo Gravatar Says:

    Hi Sandra,

    We’d be happy to help, do you have a link to the page that you are having trouble with?

  3. Pierre LoubertNo Gravatar Says:

    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!

  4. DynamiXLabsNo Gravatar Says:

    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.

We want your feedback! Leave us your thoughts below.






DynamiX Web Design

DynamiX Labs is Copyright © 2010 DynamiX Web Design, LLC.
DynamiX Labs is proudly powered by WordPress

Entries & Comments.  |  thanks & about.


The DynamiX Mascot button submit it! Background
hire dynamix!