DEV Community

Cover image for A11y tips: bind label and form controls
Carlos Espada
Carlos Espada

Posted on

5 1

A11y tips: bind label and form controls

Every form control always needs to have a visible label, so that the user can know at any time which field is being filled in, even if the autocomplete attribute is used in the HTML code.

An icon can also be a visible label as long as it is labeled appropriately.

Therefore, remember to always bind a label to a form control using the for attribute of the <label> to the id attribute of the form control, which thus receives its accessible name.

<label for="name">Name</label>
<input type="text" id="name" name="name">
Enter fullscreen mode Exit fullscreen mode

In this way we obtain 3 advantages:

  • The area to activate the form control is larger, since by clicking on the <label> the associated form control receives the focus.
  • When a voice browser gives focus to a form control, it announces its associated <label>.
  • A user using voice recognition software can activate the form control by saying the name of the associated <label>.

A special case is the <input type="button"> that contain a correct value attribute, to which it is better not to associate any label as it can interfere with how some assistive technologies parse the form control. The same goes for <button>.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more