How to associate the label element with an input element with HTML?

Spread the love

Sometimes, we want to associate the label element with an input element with HTML.

In this article, we’ll look at how to associate the label element with an input element with HTML.

How to associate the label element with an input element with HTML?

To associate the label element with an input element with HTML, we set the id attribute of the input.

For instance, we write

<label for="username">Username</label> <input type="text" id="username" />

to add a label with the for attribute set to username.

And we set the id attribute of the input to the same value to associate the label with the input.

Conclusion

To associate the label element with an input element with HTML, we set the id attribute of the input.

Leave a Reply

Your email address will not be published. Required fields are marked *