HTML label tag

<label> element is used to write a caption or name for the form elements.


<form action="files/labeltag.php" method="post">
  <label>Full name: <input name="fn"> </label> <br>
  <label>Age: <input name="age" type="number"></label> <br>
  <label><input type="submit" name="submit"> </label> <br>
Try </>

Specific uses

You can use label in two ways.

Firstly you can either place input in the label element.

Secondly, You can use the for attribute of label element to associate it with input element.

Related tags

<form> form tag represents a form that collects information from a person.
<form> form structure </form>
<input> input tag defines an input field.
<input type="text" name="fullname">

Tag omission

Both opening and closing tags are necessary for the label element.

Global Attributes

All the global attributes are applicable on the label element.

Related Attributes

<label> tag attributes
for for attribute relates the label element with input element.
<label for="id of the form"></label>
form form attribute associates label element with a specific form.
<label form="id of the input element"></label>

Was this article helpful?




Get the newsletter