Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is anything except LI's allowed in a UL?

Tags:

html

We're getting some suspicious HTML from our designer. Is the following valid? (note the UL inside the UL)

<ul>     <li>1</li>     <ul>             <li>1.1</li>         <li>1.2</li>         <li>1.3</li>     </ul>     <li>2</li>     <ul>             <li>1.1</li>         <li>1.2</li>         <li>1.3</li>     </ul> </ul> 
like image 802
willem Avatar asked May 19 '11 08:05

willem


People also ask

Do you have to use Li with UL?

Zero or more li elements is the only permitted content for a ul element according to the spec. If you have a list, use the li elements and style them. If all you want from the ul is margins and padding and your data is not a list, you would be better off using a styled div.

Can I put P inside UL?

For your code to be valid you can't put any tag inside a <ul> other than an <li> .

What elements can go inside a UL?

HTML ul element can reside within APPLET, BLOCKQUOTE, BODY, BUTTON, CENTER, DD, DEL, DIV, FIELDSET, FORM, IFRAME, INS, LI, MAP, NOFRAMES, NOSCRIPT, OBJECT, TD, TH.

Can I put h2 in UL?

According to the W3C Validator using an <h2> tag inside a <li> tag is perfectly valid.


2 Answers

According to the HTML 4 specs, the XHTML 2 specs and the HTML 5 specs that code is invalid.

HTML 4

<!ELEMENT UL - - (LI)+

This means that inside a <ul> there can only be multiple <li> elements.

XHTML

Both types of lists (ul|ol) are made up of sequences of list items defined by the li element.

HTML 5

Content model:
Zero or more li and script-supporting elements.

Note that script-supporting elements are elements that are not rendered, and currently include only <script> and <template>.

like image 197
Gabriele Petrioli Avatar answered Sep 18 '22 20:09

Gabriele Petrioli


No, it is not valid. The only allowed elements inside ul are li.

Corrected sample:

<ul>     <li>         <span>1</span>         <ul>                 <li>1.1</li>             <li>1.2</li>             <li>1.3</li>         </ul>     </li>     <li>         <span>2</span>         <ul>                 <li>1.1</li>             <li>1.2</li>             <li>1.3</li>         </ul>     </li> </ul> 

Don't allow your designer to write any HTML code for you. Hire a front-end developer that really knows how to deal with HTML and XHTML.

like image 31
Daniel O'Hara Avatar answered Sep 22 '22 20:09

Daniel O'Hara