Select and option Dropdown Menus
Create dropdown selection menus with select and option.
Select and option Dropdown Menus is a free HTML Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the HTML Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The select Element
The <select> element creates a dropdown menu:
<label for="country">Country</label>
<select id="country" name="country">
<option value="us">United States</option>
<option value="gb">United Kingdom</option>
<option value="de">Germany</option>
</select>option value vs text
Each <option> has a value (sent to server) and display text:
<select name="color">
<option value="">-- Select a color --</option> <!-- placeholder -->
<option value="#ff0000">Red</option>
<option value="#00ff00">Green</option>
<option value="#0000ff">Blue</option>
</select>
<!-- value="#ff0000" is submitted; "Red" is displayed -->selected Attribute
Pre-select an option with the selected attribute:
<select name="plan">
<option value="free">Free</option>
<option value="pro" selected>Pro (Recommended)</option>
<option value="enterprise">Enterprise</option>
</select>optgroup for Categorized Options
Group related options with <optgroup>:
<select name="language">
<optgroup label="Frontend">
<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>multiple Attribute
Allow selecting multiple options with the multiple attribute:
<label for="skills">Select your skills (Ctrl+Click for multiple)</label>
<select id="skills" name="skills" multiple size="5">
<option value="html">HTML</option>
<option value="css">CSS</option>
<option value="js">JavaScript</option>
<option value="python">Python</option>
</select>
<!-- size controls how many options are visible -->
<!-- Submitted as multiple values: skills=html&skills=css -->size Attribute
The size attribute controls how many options are visible:
<!-- size=1 (default): dropdown -->
<select size="1">...</select>
<!-- size>1: list box -->
<select size="4">
<option>HTML</option>
<option>CSS</option>
<option>JavaScript</option>
<option>Python</option>
</select>disabled Options and Groups
Disable individual options or entire groups:
<select name="plan">
<option value="free">Free</option>
<option value="pro">Pro</option>
<option value="enterprise" disabled>Enterprise (Contact Sales)</option>
</select>
<select>
<optgroup label="Legacy (deprecated)" disabled>
<option value="v1">Version 1</option>
</optgroup>
</select>Styling select
Styling native <select> is limited — here is what works:
select {
appearance: none; /* remove native dropdown arrow */
-webkit-appearance: none;
width: 100%;
padding: 0.5rem 2.5rem 0.5rem 0.75rem;
border: 1px solid #ddd;
border-radius: 4px;
background-image: url("arrow-down.svg");
background-repeat: no-repeat;
background-position: right 0.75rem center;
background-size: 1rem;
cursor: pointer;
}Custom Dropdowns vs native select
Tradeoffs when considering a custom dropdown component:
- Native select — accessible by default, mobile-friendly, works without JavaScript
- Custom dropdown — full styling control, but requires full ARIA implementation and keyboard handling
Prefer native <select> for most use cases.
Reading Selected Value in JavaScript
Get or set the selected value with JavaScript:
const select = document.getElementById('country');
// Get selected value:
console.log(select.value); // e.g. 'us'
// Get selected option text:
console.log(select.options[select.selectedIndex].text);
// Set selected value:
select.value = 'de';
// Listen for changes:
select.addEventListener('change', () => {
console.log('Selected:', select.value);
});Placeholder Option Pattern
Create a non-selectable placeholder option:
<select name="role" required>
<option value="" disabled selected>-- Select your role --</option>
<option value="dev">Developer</option>
<option value="designer">Designer</option>
<option value="pm">Product Manager</option>
</select>
<!-- disabled + selected: shows as placeholder
value="" + required: fails validation if not changed -->Quick Check
Which element groups related options inside a select dropdown?
Recap: select and option
Dropdown essentials:
<select>+<option>— dropdown menuvalueon option — what is submitted to the serverselected— pre-select an option<optgroup label>— group related optionsmultiple— allow multiple selectionssize— show N options without dropdown
Frequently asked questions
Is the “Select and option Dropdown Menus” lesson free?
Yes — the full text of “Select and option Dropdown Menus” is free to read here on the web, and the HTML Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the HTML Academy course, upgrade to CoddyKit PRO.
What will I learn in “Select and option Dropdown Menus”?
Create dropdown selection menus with select and option. You practise HTML Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start HTML Academy?
No prior experience is required. HTML Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Select and option Dropdown Menus” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this HTML Academy lesson?
Yes. Every HTML Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Select and option Dropdown Menus
- Textarea for Multi-line Input
- Checkbox and Radio Button Groups
- Datalist for Autocomplete