HTML label Tag defines the label for HTML elements like select tag, textarea tag, input elements like checkboxes, text input, email, password, number, radio, search, file and more.
Table of Contents
Syntax of HTML label Tag
The Syntax of HTML label Tag is shown below, It has both starting tag and ending tag.
<label>Name</label>
Usage of HTML label Tag
HTML label Tag is used to define the label of HTML elements. It is used to help the user in understanding the purpose of particular element.
It is also used for screen readers which reads out loud the label of particular element when focus is on that element.
It also helps in improving the user experience, a user can select any input element by simply clicking on it's label, this is only possible when the label and it's related html element are bound together.
HTML label Tag is an inline element.
Example of HTML label Tag
Simple example of HTML label Tag is shown below.
<label for="name">Name:</label>
<input id="name" type="text" name="user_name">
Output
In above example a label (Name) is used to specify the purpose of the text input field.
Notice that the value of for attribute in label tag is equal to the value of id attribute in input field. This binds the two together and user can select input field by simply clicking on the text of it's related label element.
Browser Support for HTML label Tag
HTML label Tag is supported by all major browsers including Safari and Internet Explorer.
Global Attributes Support in HTML label Tag
The HTML label Tag supports all Global Attributes.
Event Attributes Support in HTML label Tag
The HTML label Tag supports all Event Attributes.
HTML label Tag Video
Watch our video on HTML label Tag.