Home >Web Front-end >CSS Tutorial >Is Using a Div as a Direct Child of a UL Element Valid HTML?

Is Using a Div as a Direct Child of a UL Element Valid HTML?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-11 18:49:15840browse

Is Using a Div as a Direct Child of a UL Element Valid HTML?

Can I Use Div as a Direct Child of UL?

While browsers may render the following code without issue:

<ul>
   <div>
   </div>
</ul>

the HTML specification dictates that the only valid child element of ul is li.

HTML 4:

<ELEMENT UL - - (LI)+                 -- unordered list -->

HTML 5:

Content model:
Zero or more li elements.

Therefore, using div as a direct child of ul is not allowed according to the HTML specifications. This is in contrast to the information provided in the linked CSS-Tricks forum discussion.

The above is the detailed content of Is Using a Div as a Direct Child of a UL Element Valid HTML?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn