Is it ok to use <li>
tags without parent tags?
i.e.
<li> some copy
or must it be..
<ul> (substitute your favorite list type)
<li> some copy
</ul>
Links on the subject:
If by OK you mean "correct, follows standards and will validate" then no. Per the spec, only OL and UL can contain LI. (MENU and DIR are deprecated)
If by OK you mean "will render" then yes.
Also, to be "OK" by the first definition, you must also close your LI tags. Every tag must either be self-closing (/>
) or have a corresponding closing tag. Here's a quick and simple explanation of correct XHTML (and honestly, good HTML should conform to these as well. No reason not to.)
No, using a li
element without a parent ul
or ol
element would be invalid.
Proper HTML (not to mention strict XHTML) should be:
<ul>
<li>whatever</li>
</ul>
No, that would definitely be invalid (X)HTML. I mean, you could, and the browser might render it correctly if you're lucky (IE in particular, as it tends to be especially lenient), but there's far from any guarantee. You should always enclose <li>
tags with either <ul>
(unordered list) or <ol>
(ordered list). Why wouldn't you want to anyway?
li = list item, if it's without parents where's the list?
No, while it might work in some browsers, it is invalid HTML.
I checked the validation of the code below at Markup Validation Service of W3C :
<li>item 1</li>
<li>item 2</li>
and the result is :
document type does not allow element "LI" here; missing one of "UL", "OL", "DIR", "MENU" start-tag