Forms Specialist reference: Labels -- The Foundation
In the kit: .github/skills/forms-specialist/references/labels-the-foundation.md.
-
This file as plain text, at
https://letitglow.app/ahg/kit/raw/.github/skills/forms-specialist/references/labels-the-foundation.md - Everything in the kit
Copy it into ChatGPT or another assistant
Read the plain text first
Forms Specialist reference: Labels -- The Foundation
Part of the forms-specialist skill. Read this only when the task reaches these sections.
Labels -- The Foundation
Every form control MUST have a programmatically associated label. Visual proximity is not enough -- screen readers need explicit association.
Standard Pattern
<label for="email">Email address</label>
<input id="email" type="email" autocomplete="email">Requirements:
<label>element withforattribute matching the input'sid- Never use
placeholderas the only label -- it disappears on input and has poor contrast - A
placeholderon a labelled field is exposed as a hint, not a second name. Do not put instructions or format rules only in it; put them in persistent help text linked witharia-describedby, and drop a placeholder that only repeats the label - Never use
aria-labelwhen a visible label is possible -- sighted users benefit from visible labels too - Label text must be descriptive. "Email address" not "Input 1"
- Clicking a
<label>activates its associated control (ARIA labeling viaaria-label/aria-labelledbydoes NOT provide this click behavior -- this is why<label>is always preferred) - Implicit labels (wrapping input inside
<label>) work but are less well-supported than explicitfor/idassociation
When aria-label Is Acceptable
Only when a visible label genuinely cannot exist:
<!-- Search input with visible button -->
<input type="search" aria-label="Search products">
<button>Search</button>
<!-- Icon-only clear button inside an input -->
<button aria-label="Clear search">
<svg aria-hidden="true">...</svg>
</button>When to Use aria-labelledby
When the label text comes from multiple elements or is already visible elsewhere:
<h2 id="billing-heading">Billing Address</h2>
<input aria-labelledby="billing-heading street-label" id="street">
<span id="street-label">Street</span>Labels for Wrapped Inputs
This pattern works but the explicit for/id association is preferred:
<!-- Works but less explicit -->
<label>
Email address
<input type="email">
</label>
<!-- Preferred -- explicit association -->
<label for="email">Email address</label>
<input id="email" type="email">