How to use the label elements’ for attribute on radio buttons with HTML?

Spread the love

Sometimes, we want to use the label elements’ for attribute on radio buttons with HTML.

In this article, we’ll look at how to use the label elements’ for attribute on radio buttons with HTML.

How to use the label elements’ for attribute on radio buttons with HTML?

To use the label elements’ for attribute on radio buttons with HTML, we set the id of the radio button to match the for attribute of the label.

For instance, we write

<input type="radio" id="r1" /><label for="r1">button text</label>

to set the id of the radio button and the label’s for attribute to r1.

Conclusion

To use the label elements’ for attribute on radio buttons with HTML, we set the id of the radio button to match the for attribute of the label.

Leave a Reply

Your email address will not be published.