Lesson 2 of 8 · 9 min · 1 hands-on step
Forms & Inputs
Collect information from users with accessible, well-labelled forms.
Forms collect input
<form>
<label for="name">Your name</label>
<input id="name" type="text" placeholder="Ada Lovelace" required />
<label for="level">Experience</label>
<select id="level">
<option>Total beginner</option>
<option>Some experience</option>
</select>
<label>
<input type="checkbox" /> Email me new lessons
</label>
<button type="submit">Start</button>
</form>
Input types do work for you
| Type | You get |
|---|---|
email |
format check + email keyboard on phones |
password |
hidden characters |
number |
number keyboard, min/max |
date |
a date picker |
checkbox / radio |
yes/no and pick-one options |
Labels aren't optional
Every input needs a <label>. Clicking the label focuses the input (bigger tap target on phones), and screen readers read it out. Placeholder text is not a label: it disappears when you type.
Built-in validation
required, minlength, min, max and type make the browser check input before submitting, for free. You'll add JavaScript checks later, and the server must always check again, because users can bypass anything in the browser.
🧪 Practice
Build a <form> with:
- an email input (
type="email",id="email") with a<label for="email"> - a password input (
type="password",id="password") with its own label - a submit
<button>that saysSign up
Make both inputs required.
<form> </form>
Output appears here. Press Run or Ctrl/⌘ + Enter.
✅ Check your understanding
Why connect a label to its input with for/id?
What does type="email" give you for free?
Create a free account to track your progress.