Support0

HTML select playground

Explore select with controls to edit its label, reorder options, create optgroups, add hr separators, and test multiple and size without JavaScript.

Ask AI

HTML select playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.
HTML
<label for="baseline-select">Choose a technology</label>
<select id="baseline-select" name="baseline-choice">
  <option value="option-1" selected>Select an option</option>
  <hr />
  <optgroup label="Frontend">
    <option value="html">HTML</option>
    <option value="css">CSS</option>
    <option value="javascript">JavaScript</option>
  </optgroup>
  <optgroup label="Web platform">
    <option value="web-components">Web Components</option>
    <option value="forms">Forms</option>
  </optgroup>
</select>

Educational guide to native select

Choose from options with the browser’s own control

select provides a closed list of options, an accessible name, and form data. Learn what users see, what is selected, and what is submitted without rebuilding its interaction.

Mental model

Label, choice, and data serve different purposes.

  1. label → id

    for identifies the select and gives it a meaningful name.

  2. option → value

    Text explains the choice; value keeps its identifier.

  3. name → data

    The form collects the value of each selected, enabled option.

Static diagram: visible text and the data contract“Professional” can submit plan=pro. Translating the label does not have to change the identifier processed by the server.

id associates the label; name identifies the data. A single select is usually a dropdown; multiple or size greater than one can produce a list box. The browser provides semantics, focus, and selection. Appearance and picker depend on the platform.

Label and submitted value

Keep a visible label and stable values.

for must match a unique id. Each option displays text and supplies its value; omitting value uses its text. Without name, the control contributes no form entry. selected defines the initial selection: after a change, the current state lives in the control, rather than an attribute that is automatically rewritten.

A readable name and a different data value

Professional is initially selected and the data is plan=pro. Change plans: the control keeps its label and selection remains exclusive.
A readable name and a different data value
<form id="select-guide-basic-form" class="select-scene-basic">
  <label for="select-guide-plan">Plan</label>
  <select id="select-guide-plan" name="plan">
    <option value="starter">Starter</option>
    <option value="pro" selected>Professional</option>
  </select>
</form>
:root {
  color-scheme: light dark;
}

.select-scene-basic {
  display: grid;
  gap: 1rem;
  min-inline-size: 0;

  select {
    box-sizing: border-box;
    min-inline-size: 0;
    max-inline-size: 100%;
    min-block-size: 2.75rem;
    font: inherit;

    &:focus-visible {
      outline: 3px solid light-dark(oklch(0.46 0.14 261), oklch(0.82 0.18 261));
      outline-offset: 3px;
    }
  }

  p {
    margin: 0;
  }
}

The examples are local forms with no submit button or service destination. You can try the controls without sending data. In your real form, define action/method and validate allowed values on the server; a closed browser list does not prevent tampered requests.

Options, groups, and availability

Group by meaning and explain what cannot be chosen.

optgroup uses label to name a group; its heading is not a selectable option. Groups cannot be nested. disabled on an option prevents choosing it; on optgroup it disables its options. Keep descriptive names instead of relying on gray tones to explain availability.

Groups with a disabled option and a disabled group

CSS belongs to Foundations. WebGPU says “Unavailable” and WebXR is inside a disabled group. Neither destination can be chosen through native interaction.
Groups with a disabled option and a disabled group
<form id="select-guide-groups-form" class="select-scene-groups">
  <label for="select-guide-technology">Technology</label>
  <select id="select-guide-technology" name="technology">
    <optgroup label="Foundations">
      <option value="html">HTML</option>
      <option value="css" selected>CSS</option>
    </optgroup>
    <optgroup label="Advanced APIs">
      <option value="javascript">JavaScript</option>
      <option value="webgpu" disabled>WebGPU (Unavailable)</option>
    </optgroup>
    <optgroup label="Unavailable" disabled>
      <option value="webxr">WebXR</option>
    </optgroup>
  </select>
</form>
:root {
  color-scheme: light dark;
}

.select-scene-groups {
  display: grid;
  gap: 1rem;
  min-inline-size: 0;

  select {
    box-sizing: border-box;
    min-inline-size: 0;
    max-inline-size: 100%;
    min-block-size: 2.75rem;
    font: inherit;

    &:focus-visible {
      outline: 3px solid light-dark(oklch(0.46 0.14 261), oklch(0.82 0.18 261));
      outline-offset: 3px;
    }
  }

  p {
    margin: 0;
  }
}

The playground also supports hr: it adds a visual break, but inside select it is not exposed as a meaningful separator to assistive technologies. It does not replace an optgroup name. Support for hr and for basic select are separate.

required and disabled

An initial instruction should not count as a valid choice.

In a required select without multiple and with display size one, the first option in the list serves as the placeholder label option if its value is empty and it does not belong to an optgroup: keeping it selected does not satisfy required. select has no placeholder attribute. Here it stays enabled so you can return to it; required is enough to reject it during validation.

A required choice and a disabled field

The region is disabled in this demonstration; it is not submitted with the form.

Delivery starts without a valid choice. Standard or Express satisfy required. Region displays EU but is disabled: it receives no focus and is not included in form data.
A required choice and a disabled field
<form id="select-guide-constraints-form" class="select-scene-constraints">
  <label for="select-guide-delivery">Delivery (required)</label>
  <select id="select-guide-delivery" name="delivery" required>
    <option value="" selected>Choose delivery</option>
    <option value="standard">Standard</option>
    <option value="express">Express</option>
  </select>
  <label for="select-guide-region">Region (not editable)</label>
  <select id="select-guide-region" name="region" disabled aria-describedby="select-guide-region-help">
    <option value="eu" selected>EU</option>
  </select>
  <p id="select-guide-region-help">The region is disabled in this demonstration; it is not submitted with the form.</p>
</form>
:root {
  color-scheme: light dark;
}

.select-scene-constraints {
  display: grid;
  gap: 1rem;
  min-inline-size: 0;

  select {
    box-sizing: border-box;
    min-inline-size: 0;
    max-inline-size: 100%;
    min-block-size: 2.75rem;
    font: inherit;

    &:focus-visible {
      outline: 3px solid light-dark(oklch(0.46 0.14 261), oklch(0.82 0.18 261));
      outline-offset: 3px;
    }
  }

  p {
    margin: 0;
  }
}

disabled excludes the control from data and validation; it is not readonly, which select does not support. A selected but disabled option is also omitted from data. Do not disable a field if the server needs its value. If you add custom messages, associate them with the control and show errors when appropriate, without marking the whole page as failed on load.

multiple, size, and keyboard

The number of choices and the number of rows are independent decisions.

multiple allows zero or more options; size sets visible rows, not a selection limit. Without multiple there is only one choice even when size shows several rows. Adding required demands at least one selected option: the dropdown’s special empty-placeholder rule does not carry over to this list.

Several choices versus several rows

You can choose several topics. The gesture or modifier depends on your system and device.

Topics starts with HTML and CSS selected. Primary technology shows three rows and allows only one choice. The JavaScript snippet is a data-reading reference; it is not executed in the guide.
Several choices versus several rows
<form id="select-guide-multiple-form" class="select-scene-multiple">
  <label for="select-guide-topics">Topics (multiple selection)</label>
  <select id="select-guide-topics" name="topics" multiple size="4" aria-describedby="select-guide-topics-help">
    <option value="html" selected>HTML</option>
    <option value="css" selected>CSS</option>
    <option value="javascript">JavaScript</option>
    <option value="svg">SVG</option>
  </select>
  <p id="select-guide-topics-help">You can choose several topics. The gesture or modifier depends on your system and device.</p>
  <label for="select-guide-single">Primary technology (one choice, three rows)</label>
  <select id="select-guide-single" name="primary" size="3">
    <option value="html">HTML</option>
    <option value="css" selected>CSS</option>
    <option value="javascript">JavaScript</option>
  </select>
</form>
:root {
  color-scheme: light dark;
}

.select-scene-multiple {
  display: grid;
  gap: 1rem;
  min-inline-size: 0;

  select {
    box-sizing: border-box;
    min-inline-size: 0;
    max-inline-size: 100%;
    min-block-size: 2.75rem;
    font: inherit;

    &:focus-visible {
      outline: 3px solid light-dark(oklch(0.46 0.14 261), oklch(0.82 0.18 261));
      outline-offset: 3px;
    }
  }

  p {
    margin: 0;
  }
}
const form = document.querySelector('#select-guide-multiple-form');
const data = new FormData(form);
const topics = data.getAll('topics'); // ["html", "css"]

Submission repeats the same key: topics=html&topics=css. select.value and FormData.get() return only the first value; use selectedOptions or FormData.getAll() to collect them all. Do not add [] to name unless your server requires it, or convert data with Object.fromEntries if repeated keys must be preserved.

Reach the control with Tab and leave with Tab or Shift+Tab. Arrow keys move through options; typing characters usually searches their text. Opening and confirming the picker varies by system. In desktop multiple lists, Ctrl/Cmd commonly toggles options and Shift extends a range with the pointer; keyboard shortcuts for noncontiguous choices are not uniform. Test your target browser, OS, screen reader, and device without intercepting those keys.

For a small number of multiple choices that should be discoverable without learning modifiers, consider a checkbox group. Do not add role="menu", tabindex on options, or a custom keyboard controller to native select. Changing a choice should not unexpectedly navigate or submit the form.

Choosing a control

Start with the data type and the interaction the person needs.

Native select fits answers that must belong to a closed list. For a few exclusive options, radios expose every choice without opening a picker. Do not use select as a substitute for navigation links.

input with datalist suggests values and permits others that are valid for the input. It does not enforce list membership or guarantee a uniform autocomplete experience. The datalist guide explains its support and accessibility limits.

Customizable select keeps the select element and extends its presentation through pieces such as appearance: base-select and ::picker(select). Support must be assessed separately and a native alternative retained. See its guide for rich HTML, picker, and fallback; these examples do not need it.

field-sizing addresses sizing based on content. It does not change the closed list, submission rules, or keyboard. accent-color is not an API for tinting the whole select either; separate semantics, sizing, and appearance.

Common mistakes

Check association, data, and state before adding logic.

The choice does not reach the server

Expected result
Receive the identifier of the chosen option.
Cause
name is missing, the control has no form association, or the control/option is disabled.
Solution
Check name, the owning form, and disabled; inspect FormData and validate values on the server.

The instruction satisfies required

Expected result
Require a real choice in the dropdown.
Cause
A nonempty value is used, the instruction is inside optgroup, or the special rule is expected with multiple/size greater than one.
Solution
For a one-row required dropdown, use the first direct option with value="". Design list-box and multiple-selection validation separately.

Only one selected topic appears

Expected result
Keep every choice in the data.
Cause
The code reads select.value, FormData.get(), or an object that overwrites repeated keys.
Solution
Use FormData.getAll(name) for submitted values or selectedOptions to inspect current selection.

The name disappears after choosing

Expected result
Understand which data the field requests in every state.
Cause
The first option has been used instead of a visible label.
Solution
Add an associated label using for/id and use aria-describedby for additional instructions.

Support and compatibility

The native foundation does not promise identical pickers across platforms.

Web Platform DX classifies select as Baseline Widely Available. That foundation covers selection, groups, and traditional attributes; it does not automatically establish support for hr, showPicker(), field-sizing, or Customizable select pieces. The Baseline card summarizes compatibility, not an accessibility audit.

These examples use traditional select, option, and optgroup without their own JavaScript. Native selection remains available if copying fails or JavaScript is disabled. Check focus, labels, zoom, forced colors, and the list/picker in real browsers; a desktop screenshot does not establish mobile or assistive-technology behavior.