R I S K M O N I T O R

Loading

Intelligent Cybersecurity Check for vulnerabilities now

Accessible Form Labeling for Inputs

Rule ID: label
Ruleset: axe-core 4.10
User Impact: Critical
Guidelines: WCAG 2.1 (A), WCAG 2.0 (A), WCAG 2.2 (A), Section 508, Trusted Tester, EN 301 549


How to Fix the Problem

Ensure every form input element — such as <input>, <textarea>, <select>, checkboxes, and radio buttons — has a clear, programmatically associated label.

Recommended Methods:

1. Explicit <label> with for and id attributes

This is the most reliable and accessible technique:

html
<label for="firstname">First name:</label>
<input type="text" id="firstname">

2. Implicit Label (Label Wrapping)

Enclose the input within a <label> tag:

html
<label>First name: <input type="text"></label>

3. Use aria-label for Invisible Labels

When a visible label is not feasible:

html
<input type="text" aria-label="Search">

4. Use aria-labelledby when referencing multiple label sources

This is ideal when visual labels are elsewhere or when multiple labels apply:

html
<div id="temperature">Temperature:</div>
<div id="low">Low:</div>
<input type="text" aria-labelledby="temperature low">

Note: Always ensure that all id values used are unique.

5. Avoid Using Only Placeholder Attributes

Avoid relying solely on placeholder as it disappears when the user starts typing:

html
<input type="text" placeholder="Search"> <!-- Not recommended as the only label -->

Elements That Must Have Labels:

  • <input type="text">

  • <input type="password">

  • <textarea>

  • <input type="radio">

  • <input type="checkbox">

Exceptions:

  • <button> elements — already self-labeled

  • <input type="hidden"> — hidden from user interaction and doesn’t need a label

Common Mistake to Avoid:

html
First name: <input type="text" name="fname">

While this visually appears correct to sighted users, screen readers will not associate the text “First name:” with the input unless it is programmatically linked using <label>.

Also, avoid assigning multiple labels to a single input, and ensure help text is distinct from the label itself.


Why it Matters

Labels are critical for accessibility. Sighted users can often infer the purpose of a form field through visual proximity, but screen reader users depend entirely on programmatic associations.

Without a label:

  • Screen readers may announce the input without context, making it unclear what data is expected.

  • Fields may not receive proper focus.

  • Users with motor impairments lose the larger clickable area provided by labels.

A well-implemented label ensures that every user — regardless of their abilities — can interact with forms clearly, efficiently, and independently.


Rule Description

Each form input element must be explicitly or implicitly labeled using standard HTML or ARIA techniques. This ensures users of assistive technologies can understand and interact with form elements.


The Algorithm (in simple terms)

The rule checks that:

  • Each <input>, <textarea>, or <select> element (excluding buttons and hidden inputs) has a label.

  • The label is associated via:

    • A <label> with a for attribute referencing the input’s id, or

    • A wrapping <label>, or

    • An aria-label or aria-labelledby attribute.

  • The label text is meaningful and unique on the page.

Leave A Comment