24 Votes

HTML Validation: UL in UL causes error "ul not allowed as child of element ul in this context"

Question by Guest | Last update on 2021-04-03 | Created on 2014-06-03

Recently, I had a look at my website in an HTML Validator. I got the following error message there:

Error: ul not allowed as child of element ul in this context. (Suppressing further errors from this subtree.)

The error refers to one of my ul-lists in which I have included another nested ul-list as a sub list. It is something like this:

<ul>
  <li>A</li>
  <ul>
    <li>A1</li>
    <li>A2</li>
  </ul>
  <li>B</li>
  <li>C</li>
</ul>

Now, I wonder whether it is possible at all to create such a construction using valid HTML. As I understand of this error, this is not allowed to use an UL element as a child of another UL. Or is there any possibility to do so?

ReplyPositiveNegativeDateVotes
11Best Answer19 Votes

Sure it is possible to create nested lists with valid HTML.

You only have to note that there should always and only be LI elements directly under UL elements.

So, also your sublist has to be declared as list element surrounded by <li></li> like that:

<ul>
  <li>A</li>
  <li>
      <ul>
         <li>A1</li>
         <li>A2</li>
      </ul>
  </li>
  <li>B</li>
  <li>C</li>
</ul>

With this, the HTML Validator should not complain.
Last update on 2021-04-03 | Created on 2014-06-03

ReplyPositive Negative
44 Votes

You will need to remove the close tag of your first list item and place it after the unordered list like that:

<ul>
  <li>A
  <ul>
    <li>A1</li>
    <li>A2</li>
  </ul>
  </li>
  <li>B</li>
  <li>C</li>
</ul>

2021-07-12 at 01:53

Positive Negative
00 Votes

It wont work if he is creating an <ol>, he has to remove the closing tag for the main list item and put it after the nested ul list.
2021-07-12 at 01:55

Positive Negative
00 Votes

But it looked different in the browser, I wanted to A1 and A2 be nested in A.
2022-12-14 at 09:59

Positive Negative
Reply
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.