{"data":{"slug":"github-thedaviddias-front-end-checklist-skills-listitem-30248b73d7a1","title":"Ensure List Items Are Properly Nested in List Containers","summary":"Fix orphan `<li>` elements by nesting them within valid list containers like `<ul>`, `<ol>`, or `<menu>` to maintain semantic structure and accessibility. This ensures screen readers can correctly announce list type and item count.","url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-listitem-30248b73d7a1","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-thedaviddias-front-end-checklist-skills-listitem-30248b73d7a1","markdown_url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-listitem-30248b73d7a1.md","download_url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-listitem-30248b73d7a1\/download","category":{"slug":"content-editorial","name":"Content & Editorial"},"editor_note":"Before applying fixes, validate the current HTML structure and ensure that any use of `<li>` for layout purposes is replaced with appropriate elements like `<div>` or `<p>`, with styling applied via CSS.","instructions":"---\nname: listitem\ndescription: \"Use when applies to HTML documents with `<li>` elements. Also applies to custom ARIA lists where `role='listitem'` must be owned by `role='list'`. Common violations occur in templating systems where list markup is split across components or in CSS resets where developers use `<li>` for layout without proper list parents.\"\nmetadata:\n  category: accessibility\n  priority: medium\n  difficulty: beginner\n  estimatedTime: \"5\"\n  source: frontendchecklist.io\n  url: https:\/\/frontendchecklist.io\/rules\/accessibility\/listitem\n---\n\n# Place list items within list containers\n\nWhen a `<li>` element exists outside a list container, screen readers lose the ability to announce critical context: NVDA and JAWS will not say 'list of 5 items' or 'item 2 of 5' because there is no list context. VoiceOver may announce the orphan `<li>` as plain text without any group context, stripping users of the structural information that helps them understand how many items exist and where they are in the list.\n\n## Quick Reference\n\n- Every `<li>` element must have a direct parent of `<ul>`, `<ol>`, or `<menu>`\n- Orphan `<li>` elements are invalid HTML per the HTML Living Standard\n- Screen readers announce list type and item count (e.g., 'list, 3 items') only when `<li>` is inside a valid list container\n- Similarly, `role='listitem'` must be owned by a `role='list'` element per WAI-ARIA requirements\n\n## Check\n\nFind all `<li>` elements in the DOM. For each, check that its direct parent element is `<ul>`, `<ol>`, or `<menu>`. Flag any `<li>` whose parent is `<div>`, `<section>`, `<nav>`, `<span>`, or any element other than those three. Also check `role='listitem'` elements to ensure their closest ancestor with a list-related role is `role='list'`.\n\n## Fix\n\nFor each orphan `<li>`: (1) Wrap it and any sibling `<li>` elements in the appropriate list container \u2014 use `<ul>` for unordered items or `<ol>` for sequentially ordered items. (2) If the `<li>` was being used purely for styling (e.g., a bullet point visual), replace it with a `<div>` or `<p>` and apply the visual style via CSS. (3) If inside a navigation element, ensure `<nav><ul><li>` nesting is maintained.\n\n## Explain\n\nThe HTML Living Standard specifies that `<li>` elements are only valid as children of `<ul>`, `<ol>`, or `<menu>`. This is a structural requirement, not a style preference. Screen readers use the list container to announce the list type ('bullet list' vs 'numbered list') and the total item count. Without the container, this context is lost entirely. Additionally, when `list-style: none` is applied to a `<ul>`, some browsers strip the list semantics \u2014 if this is intentional (e.g., a navigation menu), add `role='list'` to the `<ul>` to restore list semantics for screen readers.\n\n## Code Review\n\nReview the rendered markup and interactive states that affect Place list items within list containers. Flag exact elements, roles, labels, focus behavior, or keyboard interactions that violate the rule, and note how to verify the fix with browser accessibility tooling or assistive tech.\n\n---\n\nFor full implementation details, code examples, and framework-specific guidance,\nsee `references\/rule.md`.\n\nRule page: https:\/\/frontendchecklist.io\/rules\/accessibility\/listitem\n","use_cases":["Fix invalid `<li>` elements in templating systems where list markup is split across components.","Correct `<li>` elements used for layout without proper list parents in CSS resets.","Ensure `role='listitem'` elements are owned by `role='list'` for ARIA compliance."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/thedaviddias\/Front-End-Checklist\/blob\/e8d14d049010e2ce25afcd5e8609dfcbbe63e47e\/skills\/listitem\/SKILL.md","source_commit":"e8d14d049010e2ce25afcd5e8609dfcbbe63e47e","license":null,"version":null,"listing_approved_at":"2026-11-23","created_at":"2026-11-22T16:57:21.000000Z","updated_at":"2026-11-23T04:55:39.000000Z","seo_title":"Fix orphan list items in HTML lists","seo_description":"Ensure `<li>` elements are properly nested within `<ul>`, `<ol>`, or `<menu>` to maintain accessibility and semantic structure.","seo_keywords":["fix orphan list items","correct list item nesting","accessibility list items","aria listitem ownership","html list structure"]}}