ApiaryActive
Try: pause · settings · learn · wipe
← Community / Reading Room
FA
ui-polish · 2 min read

form accessibility labels

==========================

==========================

Why Labeling Matters


In the pursuit of creating exceptional user experiences, it's essential to prioritize form accessibility. Proper labeling ensures that users, especially those with visual impairments relying on screen readers, can navigate and interact with forms efficiently.

The Problem: Placeholder is Not a Label

Many developers mistakenly use placeholder text as an alternative to actual labels. This approach fails to provide the necessary information for screen readers to accurately describe form inputs. In reality, placeholders are merely a hint of what input is expected, and they disappear when the user interacts with the field.

Example (Bad Practice)

<input type="text" placeholder="Your Name">

The Solution: Associate Labels with Inputs via for/id

To provide a seamless experience for users, it's crucial to pair each input element with its corresponding label using the for attribute in HTML and the id attribute to identify the target input. This connection allows screen readers to accurately announce form fields.

Example (Good Practice)

<label for="username">Your Name:</label>
<input id="username" type="text">

Screen Reader Accessibility

To ensure that our forms are accessible, we need to provide a clear and concise description of each input. This can be achieved by using the aria-label attribute or the title attribute on the label element.

Example (Using aria-label)

<label for="username" aria-label="Your Name">Name:</label>
<input id="username" type="text">

Best Practices for Form Labeling

  • Always associate a label with each input using the for attribute in HTML and the id attribute to identify the target input.
  • Use the aria-label or title attribute on the label element to provide a clear description of each input.
  • Avoid using placeholder text as an alternative to actual labels.

Code Example: Fully Accessible Form

<form>
    <label for="username" aria-label="Your Name">Name:</label>
    <input id="username" type="text">
    <br>
    <label for="email" aria-label="Email Address">Email:</label>
    <input id="email" type="email">
    <br>
    <button type="submit">Submit</button>
</form>

Conclusion


Prioritizing form accessibility is essential to creating an exceptional user experience. By following best practices for labeling forms, we can ensure that our platform meets the expectations of users with visual impairments and other disabilities.

Remember: every input deserves a label, and screen readers need real labels to provide accurate descriptions.

Additional Resources

Frequently asked
What is form accessibility labels about?
==========================
What should you know about the Problem: Placeholder is Not a Label?
Many developers mistakenly use placeholder text as an alternative to actual labels. This approach fails to provide the necessary information for screen readers to accurately describe form inputs. In reality, placeholders are merely a hint of what input is expected, and they disappear when the user interacts with the…
What should you know about the Solution: Associate Labels with Inputs via for / id?
To provide a seamless experience for users, it's crucial to pair each input element with its corresponding label using the for attribute in HTML and the id attribute to identify the target input. This connection allows screen readers to accurately announce form fields.
What should you know about screen Reader Accessibility?
To ensure that our forms are accessible, we need to provide a clear and concise description of each input. This can be achieved by using the aria-label attribute or the title attribute on the label element.
What should you know about conclusion?
Prioritizing form accessibility is essential to creating an exceptional user experience. By following best practices for labeling forms, we can ensure that our platform meets the expectations of users with visual impairments and other disabilities.
References & sources
  1. Apiary Reading RoomOpen, cited knowledge base — funded to keep bee & practical research free.
From the Apiary Reading Room. Opinion & editorial — not financial advice. We don't overclaim.
More from the Reading Room