Checkbox Group

Group related checkboxes with a fieldset and legend for clear screen reader announcements and logical form structure.

intermediate
1.3.1 Info and Relationships (Level A)3.3.2 Labels or Instructions (Level A)4.1.2 Name, Role, Value (Level A)
❌

The Bad (Inaccessible)

<div class="checkbox-container">
  <p>Select your interests:</p>
  <div>
    <input type="checkbox" id="music">
    <span>Music</span>
  </div>
  <div>
    <input type="checkbox" id="sports">
    <span>Sports</span>
  </div>
  <div>
    <input type="checkbox" id="art">
    <span>Art</span>
  </div>
</div>
βœ…

Accessibility-Ready Code

<fieldset>
  <legend>Select your interests:</legend>
  <div>
    <input type="checkbox" id="music" name="interests" value="music">
    <label for="music">Music</label>
  </div>
  <div>
    <input type="checkbox" id="sports" name="interests" value="sports">
    <label for="sports">Sports</label>
  </div>
  <div>
    <input type="checkbox" id="art" name="interests" value="art">
    <label for="art">Art</label>
  </div>
</fieldset>

The Standard

Checkbox groups must be wrapped in a <fieldset> with a <legend> to provide context. This ensures screen readers announce the group’s purpose before each checkbox.

WCAG Criteria

  • 1.3.1 Info and Relationships (Level A): Form controls must be grouped logically.
  • 3.3.2 Labels or Instructions (Level A): Labels must be programmatically associated.
  • 4.1.2 Name, Role, Value (Level A): Checkbox state must be determinable.

❌ The Bad (Inaccessible)

What’s Wrong?

  1. No Fieldset/Legend: Screen readers don’t know the checkboxes are related.
  2. No Label Association: Using <span> instead of <label for=""> breaks click-to-toggle.
  3. Missing Name Attribute: Form submission won’t group values correctly.

βœ… The Good (Accessibility-Ready Code)

Why This Works

  1. Fieldset Groups Inputs: Screen reader announces: β€œSelect your interests, group”.
  2. Legend = Group Label: Provides context before reading individual options.
  3. Label Association: Clicking the text toggles the checkbox.

Accessibility Checklist

  • Wrap related checkboxes in a <fieldset>.
  • Use <legend> to describe the group purpose.
  • Associate each <label> with its checkbox using for and id.
  • Include a name attribute for form submission.
  • Ensure visible focus states on checkboxes.
πŸ“ Perfect Implementation Reference
<fieldset>
  <legend>Select notification types:</legend>
  <input type="checkbox" id="email" name="notify" value="email">
  <label for="email">Email</label>
</fieldset>

Technical Deep Dive

The Accessibility Tree

Role: group
Name: "Select your interests"
Children:
  - Role: checkbox, Name: "Music", State: unchecked
  - Role: checkbox, Name: "Sports", State: unchecked
  - Role: checkbox, Name: "Art", State: unchecked

Focus Flow

  1. Tab Key: Moves focus to each checkbox in order.
  2. Space Key: Toggles the checkbox state.
  3. Label Click: Triggers the associated checkbox.
πŸ§ͺ

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 Checkbox 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