

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML <label> for Attribute
The for attribute of the <label> element is used to set an element with a label.
Syntax
Following is the syntax −
<label for="id">
Above, id is the associated element id.
Example
Let us now see an example to implement the for attribute of <label> element −
<!DOCTYPE html> <html> <body> <h2>Last Semester Results</h2> <form> <fieldset> <legend>Result</legend> <label for="stinfo">Student:</label> <input type="text" id ="stinfo" value="Jack"><br> <label for="sub">Subject:</label> <input type="text" value="Maths"><br> <label for="rank">Rank:</label> <input type="number" value="8"><br> </fieldset> </form> </body> </html>
Output
This will produce the following output −
In the above example, we have a form with some fields −
<form> <fieldset> <legend>Result</legend> <label for="stinfo">Student:</label> <input type="text" id ="stinfo" value="Jack"><br> <label for="sub">Subject:</label> <input type="text" value="Maths"><br> <label for="rank">Rank:</label> <input type="number" value="8"><br> </fieldset> </form>
We have set the label for the field using for attribute of the <label> element, for example −
<label for="stinfo">Student:</label> <input type="text" id ="stinfo" value="Jack"><br>
Now the input type text with is stinfo will have the label “Student” since we have set it with label for −
<label for="stinfo">Student:</label>
- Related Questions & Answers
- HTML for Attribute
- HTML <output> for Attribute
- Add a label for a form control in HTML?
- HTML DOM Label Object
- HTML DOM Option label Property
- HTML DOM Label htmlFor Property
- HTML DOM Track label Property
- HTML accept Attribute
- HTML accesskey Attribute
- HTML autofocus Attribute
- HTML checked Attribute
- HTML Class Attribute
- HTML cols Attribute
- HTML colspan Attribute
- HTML content Attribute
Advertisements