listitem
它能做什么
这项技能找出放在列表之外的列表项,例如放在 div 或 span 中的列表项,并加以修复。适用于希望列表有效且无障碍的网页制作者和模板作者。
适用场景
- ✓当你请智能体检查页面或模板中列表项标记的时候。
- ✓当组件把列表标记拆分到多个部分,而你怀疑某些列表项没有父级列表的时候。
- ✓当你审查自定义 ARIA 列表,并想确认列表项角色位于列表角色之内的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/listitem/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我检查网站上是否有列表项缺少外层列表容器。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查每个列表项的父元素是否为 ul、ol 或 menu。如果不是,它会把这些项目包裹在正确的列表容器中。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Place list items within list containers
When 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.
Quick Reference
- Every
<li>element must have a direct parent of<ul>,<ol>, or<menu> - Orphan
<li>elements are invalid HTML per the HTML Living Standard - Screen readers announce list type and item count (e.g., 'list, 3 items') only when
<li>is inside a valid list container - Similarly,
role='listitem'must be owned by arole='list'element per WAI-ARIA requirements
Check
Find 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'.
Fix
For each orphan <li>: (1) Wrap it and any sibling <li> elements in the appropriate list container — 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.
Explain
The 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 — if this is intentional (e.g., a navigation menu), add role='list' to the <ul> to restore list semantics for screen readers.
Code Review
Review 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.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/accessibility/listitem
常见问题
为什么列表项需要列表父元素?
没有父级列表,屏幕阅读器就无法告诉用户共有多少项,以及他们在列表中的位置。
哪些父元素是允许的?
这项技能把 ul、ol 和 menu 列为列表项的有效父元素。
自定义的 role 属性呢?
这项技能还会检查带有 listitem 角色的元素是否位于带有列表角色的元素之内。
详情
作者的原始描述
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.
热度
- GitHub 星标
- 75k
- 排名
- #2925
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。