Performance: List use cases in layout
Using lists in layout affects DOM size and rendering speed, impacting page load and visual stability.
<nav><ul><li><a href="#">Home</a></li><li><a href="#">About</a></li><li><a href="#">Contact</a></li></ul></nav>
<div><div>Home</div><div>About</div><div>Contact</div></div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Flat semantic list with specified image sizes | Low (few nodes, shallow depth) | Minimal (single layout pass) | Low (simple paint) | [OK] Good |
| Deeply nested lists without size attributes | High (many nodes, deep nesting) | Multiple reflows (layout thrashing) | High (complex paint) | [X] Bad |
| Using divs instead of lists for menus | Medium (extra nodes for styling) | Extra style recalculations | Medium (complex paint) | [!] OK |
<ul>) in web layout?<ul>) are used to show items that do not require a specific order.<ol> tag creates numbered (ordered) lists.<ol> is the correct choice.<ol> <li>Mix ingredients</li> <li>Bake for 30 minutes</li> <li>Let cool</li> </ol>
<ol> tag<ol> tag creates a numbered list.<li> usage inside <ol><li> is a list item, so the browser shows a numbered list with these items.<ul> <ul>Item 1</ul> <ul>Item 2</ul> </ul>
<ul><li> tags, not <ul>.<ul> inside <ul> creates invalid structure and breaks the list.<ul>) because order is not important.role="menubar" to <ul> and role="menuitem" to <li> improves accessibility and keyboard navigation.Pass the test and this pattern moves unknown