The HTML <label> tag is used to add a label to a form control like text, textarea etc.
<!DOCTYPE html> <html> <head> <title>HTML label Tag</title> </head> <body> <label for = "email">EMAIL-ID:<br /> <input type = "email" value = "" name = "emailid" size = "30" placeholder = "Enter a valid email address"> <br /> <br /> <label for = "phone">PHONE NO:<br /> <input type = "text" value = "" name = "phno" size = "30" maxlength = "10" placeholder = "Enter a valid phone number" pattern = "[0-9]{10}"> <br /> <br /> </body> </html>
This will produce the following result −
This tag supports all the global attributes described in − HTML Attribute Reference
The HTML <label> tag also supports the following additional attributes −
Attribute | Value | Description |
---|---|---|
form![]() |
form_id | It specifies one or more forms the label belongs to |
for | control id | Specifies the input control that this label is for. This value must be the same as the value in the input control's "id" attribute. |
This tag supports all the event attributes described in − HTML Events Reference
Chrome | Firefox | IE | Opera | Safari | Android |
---|---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes | Yes |