A label gives a form control a visible name and a larger activation target.
HTML labels: bind each control to a durable accessible name
Use it for a real task
The receipt ID field uses for and id so the label remains associated even if layout wrappers are added. Helper text gets its own id and is referenced by aria-describedby. A placeholder may show an input hint, but it disappears or changes during editing and should not carry the only name.
<label for="receipt-id">Receipt ID</label>
<input id="receipt-id" name="receipt_id" type="text"
autocomplete="off" aria-describedby="receipt-hint">
<p id="receipt-hint">Use the code printed at the top of the receipt.</p>What the markup guarantees
The server still needs to validate the received ID. Avoid duplicate ids across repeated form rows; an explicit label may then point at the wrong control.
Cost and limits
A correct label adds no script cost and makes click and touch targets more forgiving. The main maintenance risk is renaming an id without updating for or aria-describedby.
Common Mistakes
- Do not use placeholder as the sole label.
- Keep for equal to one unique control id.
- A visual heading near a field does not automatically name that field.
Connected lessons
- HTML forms: choose GET for retrieval and POST for a state change
- HTML constraint validation: improve feedback without trusting the browser
- HTML focus order: use native controls and keep DOM order usable
Related: HTML forms: choose GET for retrieval and POST for a state change.
Related: HTML constraint validation: improve feedback without trusting the browser.
Related: HTML radio and checkbox controls: submit choices with explicit values.
Related: HTML select and textarea: preserve meaningful values and editable text.
Related: HTML focus order: use native controls and keep DOM order usable.
Related: HTML required versus aria-required: semantics do not replace validation.
Related: HTML receipt review form project: one native flow with clear server boundaries.
Related: HTML contenteditable versus textarea: choose the data model first.
Related: HTML status region: announce a changed result without stealing focus.
Related: HTML form help: connect visible instructions and errors to a control.
Related: HTML placeholder versus label: keep field identity visible.
Continue with HTML search form: pair a search landmark with a real GET result route.
Related CSS decisions
Continue with: Browser forms: treat preview, submit, and server validation separately.
Continue with the connected Web Development lesson: Accessible forms: connect labels, errors, and focus.
