Advanced form labeling (accessible forms)

Keeping in mind accessibility when creating forms is very important. Here are some tips to advanced labeling of the form fields.

Accessible form validation

Multiple fields

With one label

<th id="namelabel" scope="col">Name</th>
<input type="text" name="name1" aria-labelledby="namelabel">
<input type="text" name="name2" aria-labelledby="namelabel">

With multiple labels

<input type="text" name="office1" aria-labelledby="cyndi officenum">

aria-describedby (hint, tooltip)

<label for="resetpass">Reset Password:</label>
<input type="password" id="resetpass" aria-describedby="pwnote"><br>
<span id="pwnote">New password must be 8-15 characters and include letters and numbers.</span>

Fieldset and legend

    <legend>Fruit juice size</legend>
      <input type="radio" name="size" id="size_1" value="small">
      <label for="size_1">Small</label>
      <input type="radio" name="size" id="size_2" value="medium">
      <label for="size_2">Medium</label>
      <input type="radio" name="size" id="size_3" value="large">
      <label for="size_3">Large</label>

When reading the above form, a screen reader will speak “Fruit juice size small” for the first widget, “Fruit juice size medium” for the second, and “Fruit juice size large” for the third.


Handling error messages

Place error message into the label field.

  <label for="fname">First Name:<span class="reqField">*</span><span class="element-invisible" id="fnameErrorHidden">You must enter your first name.</span></label><br>
  <input id="fname" type="text" name="textfield">
  <span class="errorMsg" id="fnameError">&nbsp;You must enter your first name.</span>

Futher reading


Level up your skills with useful UX, web development, and productivity tips via e-mail.


If you have any thoughts, please contact me on LinkedIn or see the contact page for more options.