HTML LABEL Without FOR Attribute and ID

by Parosa | 2020-08-10

There are two ways to associate a label with its controls (e.g. input element)


Not Using label’s for attribute.

   First Name:
   <input type="text">

control’s id is not required


Using label’s for attribute.

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

The label’s for value should match the control’s id value.

Note that control’s id attribute is required. Since id is unique, each label is associated with only one control.