Form Controls
select, textarea, checkbox, radio
Skills taught: html.select, html.textarea, html.checkbox, html.radio, html.fieldset
**select** creates a dropdown menu. Each choice is an **option** element:
<label for="country">Country</label>
<select id="country" name="country">
<option value="">-- Select country --</option>
<option value="in">India</option>
<option value="us">United States</option>
<option value="gb">United Kingdom</option>
</select>
Use **optgroup** to group related options in a dropdown:
<select name="language">
<optgroup label="Web">
<option value="html">HTML</option>
<option value="css">CSS</option>
<option value="js">JavaScript</option>
</optgroup>
<optgroup label="Backend">
<option value="python">Python</option>
<option value="node">Node.js</option>
</optgroup>
</select>
**textarea** creates a resizable multi-line text field:
<label for="bio">Bio</label>
<textarea id="bio" name="bio" rows="5" cols="40"
placeholder="Tell us about yourself..."></textarea>
**Checkboxes** are independent toggles — multiple can be selected:
<fieldset>
<legend>Languages you know</legend>
<input type="checkbox" id="html" name="skills" value="html">
<label for="html">HTML</label>
<input type="checkbox" id="css" name="skills" value="css">
<label for="css">CSS</label>
<input type="checkbox" id="js" name="skills" value="js" checked>
<label for="js">JavaScript</label>
</fieldset>
**Radio buttons** force a single choice from a group. They are grouped by sharing the same **name**:
<fieldset>
<legend>Experience level</legend>
<input type="radio" id="beginner" name="level" value="beginner">
<label for="beginner">Beginner</label>
<input type="radio" id="intermediate" name="level" value="intermediate" checked>
<label for="intermediate">Intermediate</label>
<input type="radio" id="advanced" name="level" value="advanced">
<label for="advanced">Advanced</label>
</fieldset>
Tip:
Frequently Asked Questions
What is fieldset and when should I use it?
fieldset groups related form controls under a legend label. Always use it for radio button groups and checkbox groups — it's required for accessible form design.
How do I make a dropdown that allows multiple selections?
Add the multiple attribute to select: <select multiple>. Users Ctrl+click or Shift+click to select multiple options. Style it with size attribute to show more options.
What's the difference between rows/cols and CSS width/height on textarea?
rows and cols set a fallback size in characters/rows. CSS width and height override them. Use CSS for layout control; keep rows/cols as a reasonable fallback for unstyled rendering.