What is the use of the label tag in HTML?
The <label> tag gives a name to a form field. Connect it with the field by writing the field’s id in the for attribute.
<label for="email">Email:</label>
<input type="email" id="email" name="email">
- Clicking the label puts the cursor in the field, or ticks the checkbox. This makes small checkboxes easy to use on phones.
- Screen readers read the label when the visitor enters the field.
- A
placeholderis not a replacement for a label.
You can also put the input inside the label and skip for. See HTML Forms.
Learn more about the similar topics:
| Tutorials |
|---|
| HTML Input Types |
| HTML Forms |
| Exercises & Assignments |
|---|
| Write an HTML program to create a registration form |
| Write an HTML program to create a contact form |
| Interview Questions & Answers |
|---|
| What are the different new form element types in HTML5? |
| What is the difference between GET and POST methods in an HTML form? |
| What is the use of the label tag in HTML? |