unique-id
它能做什么
这项技能检查网页上的每个 id 是否只使用一次。适用于发现标签错误或脚本抓取到错误元素的开发者。
适用场景
- ✓当页面中同一个 id 出现在多个元素上的时候。
- ✓当表单标签或 ARIA 链接没有与其字段相连的时候。
- ✓当组件库可能生成了重复 ID 的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/unique-id/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我在页面上两次使用这个组件后,表单标签就失效了。请帮我检查是否有重复的 ID。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会扫描页面,查找重复的 id 值。然后它会为每个元素分配唯一的 id,并更新使用它们的标签、ARIA 引用和脚本。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Ensure all IDs are unique
Duplicate IDs break form accessibility (labels don't connect), ARIA relationships fail, and JavaScript getElementById returns wrong elements—causing silent bugs.
Quick Reference
- Each ID must appear only once per HTML document
- Use classes for styling, IDs for unique anchors/references
- Check for duplicates introduced by component libraries
- Duplicate IDs break form labels, ARIA, and getElementById
Check
Scan this HTML document to ensure all ID attributes are unique across the entire page and properly reference related elements.
Fix
Remove duplicate ID values, ensure each ID is used only once per page, and update any references like labels, ARIA attributes, or JavaScript selectors.
Explain
Explain why unique IDs are essential for HTML validity, accessibility (form labels, ARIA), JavaScript functionality, and CSS styling.
Code Review
Review templates, server-rendered HTML, and shared components that output markup related to Ensure all IDs are unique. Flag exact elements, attributes, and routes where the rendered HTML violates the rule.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/html/unique-id
常见问题
为什么重复的 ID 很重要?
它们会破坏表单标签、无障碍链接和 getElementById 调用,可能导致难以察觉的错误。
应该用 ID 来设置样式吗?
这项技能建议用 class 来设置样式,ID 只用于唯一的锚点和引用。
组件库会导致这个问题吗?
会。这项技能指出,组件库可能会引入重复的 ID。
详情
作者的原始描述
Use when reviewing templates, rendered HTML, or shared components related to Ensure all IDs are unique. Validate the final browser-facing markup, not just the source framework abstraction.
热度
- GitHub 星标
- 75k
- 排名
- #3069
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。