Anonymous
Anonymous

Reputation: 357

Is okay to include elements other than list items in HTML lists?

I don't know which is a right way to write:

<ol><li>something</li><div>something</div><li>something</li></ol>

or

 <ol><li>something<div>something</div></li><li>something</li></ol>

I have to add a div tag and a image tag between two lists. Well I am getting the output with both code above. But I wonder which is the correct one?

Upvotes: 1

Views: 414

Answers (1)

Quentin
Quentin

Reputation: 943630

  • A div may be a child element of a li.
  • A div may not be a child element of an ol. Only li elements may be children of an ol.

So the second one is correct and the first is simply invalid.

Upvotes: 2

Related Questions