HTML <label> tag
- closing tag
- required
- void element
- no
- lives inside
- <form>
- typically holds
- the field's name/description
Where it goes
Next to the <input> it describes. Give the input an id, and give the label a for with the same value: <label for="email"> and <input id="email">.
Example
<label for="name">Name</label>
<input id="name">Open this example in the editor →
Common mistakes
- Leaving out the for and id link. The label looks right but is not connected to the field.
- Pointing for at the input's name instead of its id. The link is for to id only. name is for sending the form.
- Using placeholder text as the only label. It disappears when you start typing. A screen reader (software that reads the page aloud) does not treat it as a label.