๐ฏ By the end of this lesson you canโฆ
- Build a form with labelled inputs
- Choose the right input type
- Use select, checkbox, radio and textarea
๐ HTML ยท CSS ยท JS
form.html
๐ Tap a line to explain it
1<style>2 form { display: grid; gap: 10px; max-width: 320px; font-family: system-ui; }3 label { display: grid; gap: 4px; font-weight: 600; }4 input, select, textarea { padding: 8px; border-radius: 8px; border: 2px solid #ccc; font: inherit; }5</style>6<form>7 <label>Full name <input type="text" name="name"></label>8 <label>Email <input type="email" name="email"></label>9 <label>Age <input type="number" name="age" min="5" max="100"></label>10 <label>Class11 <select name="class">12 <option>Class 6</option>13 <option>Class 7</option>14 <option>Class 8</option>15 </select>16 </label>17 <fieldset>18 <legend>Favourite subject</legend>19 <label><input type="radio" name="subject" value="maths"> Maths</label>20 <label><input type="radio" name="subject" value="art"> Art</label>21 </fieldset>22 <label><input type="checkbox" name="news"> Send me updates</label>23 <label>Message <textarea name="msg" rows="3"></textarea></label>24 <button>Send</button>25</form>
| type | Good for |
|---|---|
text | names, short answers |
email / tel / url | contact details (right keyboard on phones) |
number / range | amounts, sliders |
date / time | calendars built in |
password | hidden typing |
checkbox / radio | many choices / one choice |
file | uploads |
๐ก Concept check
You want users to pick exactly ONE size: S, M or L. Which input?
๐ ๏ธ Feedback form
Build a form with a labelled text input for the name, a labelled email input, a dropdown with the options Good / Okay / Bad, and a Submit button.
๐ Key takeaways
- Every input needs a
<label>โ click the label and the input gets focus. - The
typechanges the keyboard and behaviour: email, number, date, passwordโฆ - Radio buttons with the same
namelet you pick one; checkboxes let you pick many.
Finished reading & practising?
Saved in this browser. Create a free account to keep it forever.