HTML Select Fields: Dropdown Lists

Master the <select>, <option>, and <optgroup> tags to build user-friendly dropdowns for your web forms.

Lesson ProgressStep 1 of 8
0 EXP

Welcome! Let's build a dropdown list. This is a key part of any web form, used for selecting from a list of options.

The Anatomy of a Select

A dropdown list is made of two main tags:

  • <select>: This is the outer container for the entire element. It also typically holds a `name` attribute, which is the "key" sent to the server.
  • <option>: This tag defines each individual choice in the list. The text you write between <option> and</optgroup> is what the user sees.
<select name="choose-one">
  <option>Choice 1</option>
  <option>Choice 2</option>
</select>

System Check

Which tag is used to define a single choice within a dropdown list?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🏗️
Select Builder

Construct a basic, well-formed dropdown list.

✍️
Option Master

Correctly use `value` and `selected` attributes.

🗂️
Group Organizer

Properly structure a dropdown using `<optgroup>`.

Mission: Build a Shipping Selector

Create a dropdown with the `name` "shipping". Include options for 'Standard', 'Express', and 'Overnight'. Each option must have a `value` (e.g., 'std', 'exp', 'on'). Make 'Standard' the default selected option.

A.D.A. Feedback:

> Awaiting input...

Challenge: Order the Grouped List

Drag the elements into the correct nested order to create a valid, grouped dropdown list.

<option>Japan</option>
<select name='country'>
</select>
<optgroup label='Asia'>
</optgroup>

Challenge: Complete the Syntax

Fill in the missing parts to create a valid dropdown that sends the value 'us' to the server.

< name="country">
  < ="us">United States</option>
<>

Consult A.D.A.

Unlock with Premium

Community Holo-Net

Peer Project Review

Submit your "Shipping Selector" project for feedback from other Net-Runners.

Beyond the Dropdown: Mastering HTML Selects

The <select> element is a cornerstone of HTML forms. It provides a simple, space-efficient way to ask a user to choose from a list of options. While it looks simple, the <select> tag and its companions, <option> and <optgroup>, offer a surprising amount of depth. Mastering them is key to building clean, accessible, and user-friendly forms.

Why use a dropdown? The primary reason is **data integrity**. By presenting a pre-defined list, you prevent typos and ensure the data you receive on your server is in a consistent, expected format.

1. The Core Anatomy: `select`, `option`, `value`, and `name`

A dropdown is built from four key pieces of information:

  • <select>: The container element that wraps the entire component.
  • `name` Attribute: Placed on the <select> tag. This is the "key" that is sent to the server. For example, `name="color"`.
  • <option>: An individual item in the list. The text between <option> and </optgroup> is what the user sees.
  • `value` Attribute: Placed on the <option> tag. This is the "value" that is sent to the server. If a user selects the option, the server receives `name=value` (e.g., `color=red`).

It is **critical** to understand the difference between the option's text and its `value`. The text is for humans; the `value` is for the machine.


<select name="color">
  <option value="c1">Red</option>
  <option value="c2">Green</option>
</select>

2. Organizing Long Lists: `optgroup`

When your list has more than 10-15 items, it can become difficult to scan. You can organize related options under a heading using the <optgroup> tag. The heading itself is set with the `label` attribute and is not selectable.

<select name="vehicle">
  <optgroup label="Cars">
    <option value="volvo">Volvo</option>
    <option value="audi">Audi</option>
  </optgroup>
  <optgroup label="Bikes">
    <option value="honda">Honda</option>
    <option value="yamaha">Yamaha</option>
  </optgroup>
</select>

3. Advanced Functionality: `selected`, `multiple`, `size`, `disabled`

You can control the default state and behavior of your select box with several boolean attributes:

  • `selected`: Add this attribute to an <option>to make it the default choice when the page loads.
  • `multiple`: Add this to the <select> tag to allow users to select multiple options (usually with Ctrl/Cmd + click). This often changes the UI from a dropdown to a list box.
  • `size`: Add this to the <select> tag to define how many options are visible at one time. A `size` greater than 1 also turns the dropdown into a list box.
  • `disabled`: Can be added to <select>,<optgroup>, or <option> to prevent interaction.
  • `required`: Add to the <select> tag to ensure the user makes a choice before submitting the form.

4. Accessibility is Non-Negotiable: `label`

A dropdown list is useless if a user doesn't know what it's for. Every<select> element **must** be paired with a <label> tag. The `for` attribute of the `label` must match the `id` attribute of the <select>.

✔️ Good Practice


<label for="car-select">Choose a car:</label>
<select name="cars" id="car-select">
  ...
</select>

This links the label and select, allowing screen reader users to understand the context and all users to click the label to focus the box.

❌ Bad Practice


<p>Choose a car:</p>
<select name="cars">
  ...
</select>

This is visually identical but inaccessible. A screen reader will just announce "Dropdown list" with no context.

5. When NOT to Use `select`?

A <select> is great, but not always the best tool.

  • For 2-4 options: Consider Radio Buttons. They are faster to use as all options are visible at once.
  • For "suggestions": If you want to provide a list of suggestions but also allow the user to type their own, use an `<input>` with a `<datalist>`.
Key Takeaway: Use <select> to ensure data integrity from a medium-to-long list of options. Always use a <label>, group long lists with<optgroup>, and never confuse the user-facing text with the server-facing `value`.

HTML Select & Form Glossary

<select>
The container element that creates a dropdown list or a list box.
<option>
An individual item within a <select> list. The text between the tags is displayed to the user.
<optgroup>
A tag used to group related <option> elements under a non-selectable heading.
`name` Attribute
Used on the <select> tag. This is the 'key' that is sent to the server when the form is submitted (e.g., `name="country"`).
`value` Attribute
Used on the <option> tag. This is the 'value' associated with the `name` key that is sent to the server (e.g., `value="us"`). This is often different from the text the user sees.
`selected` Attribute
A boolean attribute for <option>. When present, it makes that option the default selection when the page loads.
`label` Attribute
Used on the <optgroup> tag to define the visible heading for that group of options.
`multiple` Attribute
A boolean attribute for <select>. When present, it allows the user to select more than one option.
`disabled` Attribute
A boolean attribute that can be applied to <select>,<optgroup>, or <option> to make it non-interactive and grayed out.
`required` Attribute
A boolean attribute for <select>. It specifies that the user must select a value before submitting the form.
<label> Element
A crucial accessibility element that provides a caption for a form control. It is linked to the <select> via its `for` attribute, which must match the <select> tag's `id`.

Credibility and Trust

About the Author

Author's Avatar

Todotutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching HTML and building robust and accessible web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest HTML5 specifications and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!