HTML <label for=””> Attribute

Sami C.
1 min readFeb 16, 2019

--

What?

Let’s say you would have a checkbox with a label next to it

label with checkbox

It would be nice, that whenever you click the label, the checkbox would be selected.

To achieve this we can simply use the for attribute on a label to match with an id of the input element we want to bind it with.

Example

Hopefully this was helpful and Happy coding!

--

--

Sami C.
Sami C.

Written by Sami C.

Freelance Software Engineer

No responses yet