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>
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.
For your code to be valid you can't put any tag inside a <ul> other than an <li> .
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.
According to the W3C Validator using an <h2> tag inside a <li> tag is perfectly valid.
According to the HTML 4 specs, the XHTML 2 specs and the HTML 5 specs that code is invalid.
<!ELEMENT
UL
- - (LI
)+
This means that inside a <ul>
there can only be multiple <li>
elements.
Both types of lists (
ul|ol
) are made up of sequences of list items defined by theli
element.
HTML 5
Content model:
Zero or moreli
and script-supporting elements.
Note that script-supporting elements are elements that are not rendered, and currently include only <script>
and <template>
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With