Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)75k · #2925

listitem

Skill này làm gì

Skill này tìm các mục danh sách đặt ngoài danh sách, chẳng hạn bên trong div hoặc span, rồi sửa chúng. Skill dành cho người xây web và tác giả template muốn danh sách hợp lệ và dễ tiếp cận.

Khi nào nên dùng

  • ✓Khi bạn nhờ agent kiểm tra đánh dấu mục danh sách trên trang hoặc trong template.
  • ✓Khi một component tách đánh dấu danh sách thành nhiều phần và bạn nghi ngờ có mục không có danh sách cha.
  • ✓Khi bạn rà soát danh sách ARIA tùy chỉnh và muốn xác nhận vai trò mục danh sách nằm trong vai trò danh sách.

Liên kết skill

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/listitem/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/listitem/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể kiểm tra xem có mục danh sách nào trên website của tôi bị thiếu vùng chứa danh sách không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent kiểm tra cha của từng mục danh sách có phải là ul, ol hoặc menu không. Nếu không, agent bọc các mục vào vùng chứa danh sách đúng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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 a role='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

Câu hỏi thường gặp

Vì sao mục danh sách cần có danh sách cha?

Nếu thiếu, trình đọc màn hình không thể cho người dùng biết có bao nhiêu mục và họ đang ở vị trí nào trong danh sách.

Những phần tử cha nào được phép?

Skill liệt kê ul, ol và menu là các cha hợp lệ cho mục danh sách.

Còn các thuộc tính role tùy chỉnh thì sao?

Skill cũng kiểm tra rằng phần tử có role listitem nằm trong phần tử có role list.

Chi tiết

Mô tả gốc của tác giả

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.

repo: thedaviddias/Front-End-Checklist

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2925
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự