Form Controls, Fieldsets & Constraint Validation
Go beyond basic text inputs with fieldset/legend, radio groups, select menus, datalist autocomplete, and native validation rules.
What you'll learn
- Group related radio buttons or checkboxes with <fieldset> and <legend>
- Offer choices using <select>, <optgroup>, and searchable <datalist>
- Use inputmode, autocomplete, pattern, and min/max for frictionless UX
Great forms reduce typing effort and prevent mistakes before the user hits submit.
Grouping Related Inputs with <fieldset> & <legend>
When you have a group of radio buttons (like “Preferred Track”), wrap them in <fieldset> with a <legend>. Screen readers automatically announce the legend before each radio option!
Choosing the Right Control
| Control | Best For |
|---|---|
<input type="radio"> | Choosing one option from 2–5 visible choices |
<input type="checkbox"> | Toggling zero or more independent options |
<select> | Choosing one option from a long list (e.g., country) |
<input list="..."> + <datalist> | Free-text input with native autocomplete suggestions |
<textarea> | Multi-line comments or bio text |
Fill-in-the-Blank Exercise
Accessible Radio Group
Group the radio choices accessibly using <fieldset> and <legend>.
<>
<>Experience Level</legend>
<label><input type="radio" name="level" value="beginner" /> Beginner</label>
<label><input type="radio" name="level" value="pro" /> Pro</label>
</fieldset>Try It Yourself
Test the <fieldset>, <datalist> autocomplete, and numeric min/max validation below:
No console output yet. Try calling console.log(...) in JS.
Check Your Understanding
1. How do radio buttons know they belong to the same mutually exclusive group?
Finished this lesson?
Your progress is saved locally in your browser, no account needed.