Kyle
Kyle

Reputation: 47

Can you put li elements inside a div

Ok, so I have looked around w3c and blogs and have not found an argument as to why I cannot do the following html:

<ul>
    <div><li>1</li></div>
    <div><li>2</li></div>
    <div><li>3</li></div>
</ul>

I know intuitively this doesn't look right but I can't find a reference that says you can't do it.

Upvotes: 1

Views: 6649

Answers (2)

Joey
Joey

Reputation: 1370

If you search for "HTML Validator" you can quickly run some code through one to see if it is valid or not. Div tags aren't valid as first level child elements of a ul tag. Whatever you are trying to achieve can be accomplished by styling the li tags with CSS.

Upvotes: 1

isherwood
isherwood

Reputation: 61079

No. This is invalid HTML.

Permittend content: zero or more <li> elements, eventually mixed with <ol> and <ul> elements.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul

Upvotes: 4

Related Questions