Forms
Forms let people send you information: a sign-up, an order, a search.
<form>
<label for="name">Your name</label>
<input type="text" id="name" name="name" required>
<label for="phone">Phone</label>
<input type="tel" id="phone" name="phone">
<button type="submit">Send</button>
</form>
Labels matter
Every field needs a <label>. Its for attribute must match the field's id. Then:
- screen readers read the label when the field is focused,
- tapping the label focuses the field, a bigger target on a phone.
A placeholder is not a label: it disappears as soon as you type.
The right input type
The type changes the keyboard phones show and adds free checking:
| type | Gives |
|---|---|
email |
an @ keyboard; checks for an email shape |
tel |
a number pad for phone numbers |
number |
numbers only; min and max allowed |
date |
a date picker |
password |
hidden characters |
checkbox, radio |
ticks and single choices |
Built-in validation
required, min, max, minlength and pattern make the browser check input before the form is sent, with no code at all.
Choosing from a list
<label for="size">Size</label>
<select id="size" name="size">
<option>Small</option>
<option>Large</option>
</select>
Your task
Build an order form with:
- A required email field.
- A
<select>for the cake size with at least 3 options. - A label for every field, connected with
forandid. - A submit button.