thedaviddias/Front-End-Checklist / skills/duplicate-id-active
duplicate-id-active
VerifiedUse when reviewing rendered HTML, interactive components, or design-system patterns related to Use unique IDs for active elements. Check native semantics first, then inspect keyboard behavior, focus flow, accessible names, and screen-reader output where relevant.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 1.7 KB |
| references/rule.md | markdown | 2.9 KB |
references/rule.md
View on GitHub# Use unique IDs for active elements
> All focusable or active elements must have a unique ID attribute.
**Priority:** high · **Difficulty:** intermediate · **Time:** 10 min
---
Every interactive element on a page must have a unique ID to ensure that browsers and assistive technologies can uniquely identify and interact with them.
## Code Example
```html
<!-- ✅ Good: Unique IDs for each input -->
<label for="first-name">First Name</label>
<input id="first-name" type="text">
<label for="last-name">Last Name</label>
<input id="last-name" type="text">
<!-- ❌ Bad: Duplicate IDs on active elements -->
<button id="submit-btn">Save</button>
<button id="submit-btn">Cancel</button> <!-- Error: ID must be unique -->
```
## Why It Matters
- **Focus Management**: Browsers use IDs to track which element currently has focus. Duplicate IDs can lead to focus being lost or moved to the wrong element.
- **Keyboard Navigation**: Users navigating by keyboard may find that some interactive elements are unreachable if they share an ID with another element.
- **Assistive Technology**: Screen readers often use IDs to build a map of the page's interactive controls. Duplicate IDs corrupt this map.
## Best Practices
✅ **Automate Checks**: Use linters or accessibility auditors to catch duplicate IDs during development.
✅ **Use Prefixes**: In component-based frameworks, use unique prefixes or generated IDs to avoid collisions between multiple instances of the same component.
✅ **Semantic Labels**: Always ensure `for` attributes on labels match the unique `id` of their corresponding input.
## Tools & Validation
- [W3C HTML Validator](https://validator.w3.org/)
- [Axe-core Rule: duplicate-id-active](https://dequeuniversity.com/rules/axe/4.7/duplicate-id-active)
## Exceptions
- Evaluate the rendered experience before treating a static-code smell as a blocker; interaction timing, browser behavior, and assistive technology output often determine severity.
- Not every secondary accessibility issue deserves equal weight; prioritize the issue that most directly blocks perception, operation, or understanding.
- Avoid adding redundant markup or ARIA solely to satisfy a rule when a simpler semantic implementation would eliminate the issue entirely.
## Standards
- Align the implementation with W3C WAI: WCAG Overview and verify the rendered experience, not only the source code.
- Align the implementation with MDN: Accessibility and verify the rendered experience, not only the source code.
## Verification
### Automated Checks
- Inspect the browser accessibility tree or accessibility pane for the relevant element, role, or accessible name.
- Run an automated accessibility checker such as axe or Lighthouse where applicable.
### Manual Checks
- Test the affected UI with keyboard-only navigation and confirm the rule holds in the rendered experience.
- Re-test one representative user flow with a screen reader if this rule affects a key interaction.Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |