thedaviddias/Front-End-Checklist / skills/form-labels
form-labels
VerifiedUse when reviewing rendered HTML, interactive components, or design-system patterns related to Associate labels with form controls. 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 | 2.2 KB |
| references/rule.md | markdown | 3.5 KB |
references/rule.md
View on GitHub# Associate labels with form controls
> Form inputs must have programmatically associated labels.
**Priority:** critical · **Difficulty:** beginner · **Time:** 5 min
---
Every form control must have a label that is programmatically associated with it to ensure it is accessible to all users. [MDN's `<label>` reference](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label) and WCAG form guidance both treat this as a baseline requirement, not an enhancement.
## Code Examples
### Correct Implementation
```html
<label for="email-address">Email Address</label>
<input type="email" id="email-address" name="email">
<!-- Or wrapping the input -->
<label>
Email Address
<input type="email" name="email">
</label>
```
### Incorrect Implementation
```html
<span>Email Address</span>
<input type="email" name="email">
```
## Why It Matters
- **Assistive Technology**: Screen readers announce the label when the user focuses on the input.
- **Usability**: Clicking the label moves focus to the input, providing a larger hit area for users with motor impairments or those on mobile devices.
- **Form Validation**: Browsers and tools can better associate error messages with the correct fields.
## Best Practices
✅ **Use `for` and `id`**: This is the most robust way to associate labels.
```html
<label for="first-name">First Name</label>
<input type="text" id="first-name">
```
✅ **Nested Labels**: Alternatively, you can nest the input inside the label.
```html
<label>
Last Name
<input type="text">
</label>
```
❌ **Avoid Placeholder-only labels**: Placeholders disappear when the user types and are not a substitute for labels.
```html
<!-- Avoid this -->
<input type="text" placeholder="First Name">
```
✅ **Use `<fieldset>` and `<legend>` for grouped controls**: Radio buttons and related checkboxes need a programmatic group label, not just bold text above them.
```html
<fieldset>
<legend>Preferred contact method</legend>
<label>
<input type="radio" name="contact" value="email">
Email
</label>
<label>
<input type="radio" name="contact" value="phone">
Phone
</label>
</fieldset>
```
## 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.
- Confirm every field still has a visible label after the user starts typing and after browser autofill runs.
- For radio groups and checkbox groups, confirm the shared question is announced before the individual control labels.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 |