Lesson
HTML Form Elements
10 min reading
Free CourseHTML Form Elements: Dropdowns, Textareas, Fieldsets, and Datalists
While input handles single-line fields, HTML provides specialized form elements for multi-line messages, dropdown menus, grouped sections, and autocomplete suggestions. Choosing native form controls gives you keyboard navigation and screen reader support without extra JavaScript libraries.
Specialized Form Controls
textarea: Collects multi-line text such as comments or bios. Control height withrowsand enforce character limits withmaxlength.select,option, andoptgroup: Creates a dropdown menu. Wrap related options insideoptgroup label="..."for clearer long lists.fieldsetandlegend: Visually and semantically group related fields—like shipping address fields or radio button sets—with a shared caption.datalist: Attaches a native autocomplete suggestion dropdown to a textinputvia matchinglistandidvalues while still letting users type custom entries.output: Displays the calculated result of a form formula or slider control.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Form Elements Demo</title>
<style>
form { max-width: 460px; font-family: system-ui, sans-serif; display: grid; gap: 14px; }
fieldset { border: 1px solid #cbd5e1; border-radius: 8px; padding: 14px; display: grid; gap: 10px; }
select, textarea, input { width: 100%; padding: 8px; box-sizing: border-box; }
</style>
</head>
<body>
<form>
<fieldset>
<legend>Project Preferences</legend>
<label for="framework">Primary Stack</label>
<select id="framework" name="framework">
<optgroup label="Frontend">
<option value="react">React</option>
<option value="vue">Vue</option>
</optgroup>
<optgroup label="Backend">
<option value="laravel">Laravel</option>
</optgroup>
</select>
<label for="city">City (Autocomplete)</label>
<input id="city" name="city" list="city-options" placeholder="Start typing...">
<datalist id="city-options">
<option value="Dhaka"></option>
<option value="London"></option>
<option value="Toronto"></option>
</datalist>
</fieldset>
<label for="notes">Project Notes</label>
<textarea id="notes" name="notes" rows="4" placeholder="Describe your requirements"></textarea>
</form>
</body>
</html>
Common Mistakes to Avoid
- Putting default text inside
textareavia avalueattribute: Unlikeinput,textareaplaces its initial text directly between its opening and closing tags. - Omitting
legendinsidefieldset: Screen readers announce thelegendas context for every field inside the group, so always makelegendthe first child offieldset. - Expecting
datalistto reject unlisted values:datalistonly suggests options; useselectwhen users must pick strictly from fixed choices.
Frequently Asked Questions
How do I allow multiple selections in an HTML select box?
Add the multiple boolean attribute on the select opening tag so visitors can pick more than one option.
Why use fieldset around radio buttons?
Wrapping radio buttons in fieldset with a legend ensures screen readers read the shared question before each individual radio option.
Save Your Progress
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Enterprise-Grade Security Protocol
Try it Yourself
Experiment with the code from this lesson in our interactive playground.