Is using <li> without enclosing <ul> tags dangerous?

jball picture jball · Jan 9, 2010 · Viewed 25.4k times · Source

What are the dangers of inserting <li>...</li> into a page without enclosing the item(s) in a <ul> block? For example:

<div style="border:solid 1px red;">
    <li>Item</li>
    <li>Another Item</li>
    <li>Yet Another Item</li>
</div>

Validation is the least of my concerns, I'm wondering what this might break in browsers for the end user's ability to view the page as intended.

Answer

Gregory Pakosz picture Gregory Pakosz · Jan 9, 2010

It's not valid markup at all. If it gets displayed correctly, it's only a matter of luck.

As you seem to define dangerous by "break in browsers for the end user's ability to view the page as intended", then yes it's dangerous.

Browsers are trying their best to compensate for invalid markup but there is no guarantee at all your page gets displayed correctly.

You say validation is the least of your concerns, please reconsider and have a look at Why Validate?. If you care about your page being displayed correctly with no quirks, then validate.

Finally, HTML Tidy may help you fixing existing html.

EDIT: I submitted your fragment to browsershots.org to see how it gets rendered by different browsers.