HTML - Forms (Overview)
Overview
Estimated time: 35–50 minutes
Forms collect user input. HTML provides rich semantics, validation, and accessibility hooks out of the box.
Learning Objectives
- Structure a form with labels and controls.
- Choose appropriate input types and attributes.
- Leverage built-in validation messages.
Basic form
<form action="/subscribe" method="post">
<label for="email">Email</label>
<input id="email" name="email" type="email" required>
<button type="submit">Subscribe</button>
</form>
Try it
Input types and validation
<input type="number" min="1" max="10" required>
<input type="url" placeholder="https://">
<input type="date">
Common Pitfalls
- Missing
<label>
or incorrectfor
/id
pairing. - Relying only on placeholders; they are not labels.
Checks for Understanding
- Why is a visible label important even if you have a placeholder?
- What benefit does
type="email"
provide on mobile devices?
Show answers
- Labels remain visible and are announced by screen readers; placeholders disappear on input.
- It shows an email-optimized keyboard and built-in validation.
Exercises
- Build a contact form with name, email, and message fields; ensure labels and required validation.
- Add a number input for quantity with min/max/step and verify validation.