🏷️HTML labels
giving each form field a label
Looking closer into the <form>
at our fields and their labels:
On top of most of each the form fields, we have a <label>
tag that points to the field...
...also note that when the user clicks on a <labe
l>
tag, it becomes equivalent to clicking on the field itself!
Each <label>
has a for
attribute which matches the form field's name
attribute:
The "First name" label matches the
<input>
field that has the namefname
The "Last name" label matches the
<input>
field that has the namelname
The "Gender" label matches the
<select>
field that has the namegender
However, the input
with the type
of submit (i.e. a button) does not need a label as the value text serves as the label!
Last updated