HTML <label> with for Attribute

You are Here:

HTML <label> with for Attribute

The for attribute specifies the label belongs to which input element.

The for attribute allow users to click on the text within the <label> element to toggle the control.

Note: The value of the for attribute should be same as the value of the id attribute of the element it belongs to.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <form> <label for="male">Male</label> <input type="radio" name="gender" value="male" id="male"><br> <label for="female">Female</label> <input type="radio" name="gender" value="female" id="female"><br> <label for="other">Other</label> <input type="radio" name="gender" value="other" id="other"> </form> </body> </html>

Attribute Value

ValueExplanation
element_idSpecifies the label belongs to which input element.

Reminder

Hi Developers, we almost covered 99.5% of HTML Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in HTML.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author