The correct way to write lists

This is what I thought about for a while, as I saw how they were used in practice.

Method 1

<ol> <li>List item 1</li> <li>List item 2 <ol> <li>List item 3</li> </ol> </li> <li>List item 4</li> </ol> 

This seems to me semantically correct, since the sub-list is a sub-list of this list item, however it is not very clean (the contents of the list of items are <list right next to it> ).

Method 2

 <ol> <li>List item 1</li> <li>List item 2</li> <ol> <li>List item 3</li> </ol> <li>List item 4</li> </ol> 

A cleaner, but it is not clear that this list is a sub-list of item 2 (although it is understandable by human output).

This is just a semantic markup problem, both methods represent the same content on the page.

So what do you think? Sources, where possible, are preferred, but personal use is also good. I notice that MediaWiki Heirchial's encryption methods use method 1, which leads me to believe that it is the right use.

+4
source share
3 answers

Method 2 is not valid HTML. OL not allowed as a direct child of another OL . In OL only LI allowed.

In addition, the subscription membership in clause 2 is obvious only to the reader due to indentation. Indent even with LI s, and it seems that the internal list itself is the third element. I could expect such a rendering with two numbers:

  1. List item 1
 2. List item 2
 3. 1. List item 3
 4. List item 4

Method 1 is the way to go.

+13
source

The correct method 1.

+2
source

HTML 4.01 only allows LI elements in OL. However, the closing LI tag is optional. This means that this is equivalent to your method 1:

 <ol> <li>List item 1 <li>List item 2 <ol> <li>List item 3 </ol> <li>List item 4 </ol> 

This is somewhat ambiguous for the reader where the closure is LI - although the specification is clear what it will be after the closure of OL.

XHTML 1.1 has the same limitations, but forces the use of a closing LI to make it explicit.

+2
source

All Articles