Labels and Accessible Form Structure
You'll learn how to properly connect labels to form inputs and structure forms so everyone—including people using screen readers—can navigate and complete them easily.
Why Labels Matter
Every form input needs a clear, programmatically associated label. Think of labels like name tags at a conference: they tell everyone what each input is for. For sighted users, it's a visual convenience. For screen reader users, it's essential—without proper labels, they can't tell what data an input expects.
Explicit Label Association
Use the <label> element with a for attribute that matches the input's id:
<label for="email">Email Address</label>
<input type="email" id="email" name="email">
This creates an explicit connection. Now clicking the label focuses the input, and screen readers announce "Email Address, edit text" when users navigate to it.
Alternatively, nest the input inside the label (implicit association):
<label>
Email Address
<input type="email" name="email">
</label>
Explicit association is generally preferred for flexibility and clarity.
Grouping with Fieldset and Legend
For related inputs (like radio buttons or sections), use <fieldset> and <legend> to create logical groups:
<fieldset>
<legend>Shipping Method</legend>
<label><input type="radio" name="shipping" value="standard"> Standard</label>
<label><input type="radio" name="shipping" value="express"> Express</label>
</fieldset>
The <legend> acts as a heading for the group. Screen readers announce it when entering the fieldset, providing context: "Shipping Method, group, Standard, radio button."
Form Hierarchy
Structure forms with a logical flow: group related fields, use headings where appropriate, and ensure tab order follows visual order. This creates a predictable navigation path.
Key Takeaway: Always use <label> elements explicitly associated with inputs via for/id, group related fields with <fieldset>/<legend>, and maintain logical structure—this makes forms accessible to everyone, especially screen reader users.