How does the for attribute work?

How for attributes really work for the labels and in what way it connects input element to the label?

for in the label binds to id in the input. It is only needed if the label does not wrap the input control.

<label for="id">ID</label>
<input id="id">

When the label wraps the control, it doesn’t need any binding since the control is its child element.

1 Like