Input with Label

Every form input must have a programmatically associated label. Here's how to do it right with the <label> element.

beginner
1.3.1 Info and Relationships (Level A)3.3.2 Labels or Instructions (Level A)
❌

The Bad (Inaccessible)

<span>Email Address</span>
<input type="email" id="email">
βœ…

Accessibility-Ready Code

<label for="email">Email Address</label>
<input type="email" id="email" name="email" autocomplete="email">

The Standard

A <label> element tells users (and assistive technologies) what a form field is for. Without it, a screen reader user lands on an input and hears… silence.

WCAG Criteria

  • 1.3.1 Info and Relationships (Level A): Information and relationships conveyed through presentation must be programmatically determined.
  • 3.3.2 Labels or Instructions (Level A): Labels or instructions are provided when content requires user input.

❌ The Bad (Inaccessible)

What’s Wrong?

  1. No Association: The <span> is visually near the input, but there’s no programmatic link.
  2. Screen Reader Silence: Users hear β€œedit text” with no indication of what to type.
  3. Click Target: Clicking the text doesn’t focus the input.

βœ… The Good (Accessibility-Ready Code)

Why This Works

  1. Programmatic Link: The for="email" attribute connects the label to the id="email" input.
  2. Screen Reader Clarity: Users hear: β€œEmail Address, edit text.”
  3. Click Target: Clicking the label focuses the inputβ€”a free usability win.

Accessibility Checklist

  • Every <input>, <select>, and <textarea> must have a <label>.
  • The for attribute on the label must match the id of the input.
  • Use autocomplete attributes for common fields (email, password, name).
  • Do NOT use placeholder as a replacement for a label.
πŸ“ Perfect Implementation Reference
<label for="username">Username</label>
<input type="text" id="username" autocomplete="username">

Technical Deep Dive

The Accessibility Tree

Role: textbox
Name: "Email Address"
State: focusable
πŸ§ͺ

Interactive Behavioral Lab

πŸ’»

Interactive Sandbox

LIVE PREVIEW

πŸ”¬ Technical Internals

Understand how this component is processed by the browser and Assistive Technology (AT). This section bridges the gap between visual code and the hidden logic that powers accessibility.

🌲 Accessibility Tree

The data structure used by screen readers to "see" your page. It translates HTML roles and attributes into standardized objects.

βš™οΈ Event Logic

Expected behavioral standards for keyboard navigation and state transitions. Crucial for users who don't use a mouse.

  • Focus: Highlights via :focus-visible
  • Activation: Responds to Enter and Space
  • Role: Identified as Input Pattern

🌐 Browser & Screen Reader Compatibility

Browser
Screen Reader
Status
🍎 Safari
VoiceOver
βœ“ Safe
πŸͺŸ Chrome
NVDA
βœ“ Safe
πŸͺŸ Edge
JAWS
βœ“ Safe
🦊 Firefox
NVDA
βœ“ Safe
πŸ“± iOS Safari
VoiceOver
βœ“ Safe
πŸ€– Chrome Android
TalkBack
βœ“ Safe