Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write W3C compliant multi-level bullet points in HTML?

Is it possible to write W3C compliant multi-level bullet points (unordered list) in HTML?

Nested ul can be used, but is not W3C compliant.

 <ul>      <li>myItem 1</li>      <li>myItem 2</li>      <ul>         <li>myItem 2a</li>      </ul>      <li>myItem 3</li>      <li>myItem 4</li>  </ul> 
  • myItem 1
  • myItem 2
    • myItem 2a
  • myItem 3
  • myItem 4

In Visual Studio, the above code gives the warning: Validation (XHTML 1.0 Transitional): Element 'ul' cannot be nested within element 'ul'

like image 928
Techboy Avatar asked Dec 16 '10 21:12

Techboy


People also ask

How do you make a multilevel list in HTML?

Before trying the following steps, realize that to create a multilevel list in HTML you must nest the list into another list item. Also, because HTML only has either a bullet list or number list, if you want to change the type of list, you must use CSS to create a new style type.

How do you make sub bullets in HTML?

You create an unordered list using the ul tag. Then, you use the li tag to list each and every one of the items you want your list to include. tag.

What is the correct HTML code to make a bulleted list?

An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.


2 Answers

The only valid child of either a ul or ol is an li element; an li can, however, contain a ul (or ol). To achieve your aim:

<ul>    <li>myItem 1</li>    <li>myItem 2</li>    <li style="list-style-type:none">      <ul>        <li>myItem 2a</li>      </ul>    </li>    <li>myItem 3</li>    <li>myItem 4</li>  </ul>
like image 94
David Thomas Avatar answered Sep 20 '22 03:09

David Thomas


Complementing David Thomas answer, this would remove the unwanted bullet:

<ul>     <li>myItem 1</li>     <li>myItem 2                 <ul>             <li>myItem 2a</li>         </ul>     </li>     <li>myItem 3</li>     <li>myItem 4</li> </ul>
like image 34
Marlon Avatar answered Sep 18 '22 03:09

Marlon