Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

option — an HTML choice

The option element defines a choice in select or a suggestion in datalist. It separates the label from the value and supports default selection and disabled choices.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<option value="value" selected disabled>Label</option>

option represents a choice in select or a suggestion in datalist; optgroup groups choices. A suggestion alone does not restrict typed input to the available values.

value specifies the choice's value; when absent, the value is derived from its text. A nonempty label supplies its label; otherwise the label comes from text content. Plain text is sufficient for a conventional list.

The boolean selected attribute specifies default selection, reflected by defaultSelected. The JavaScript selected property represents the current state. Without multiple on select, do not mark more than one choice with the selected attribute.

disabled prevents user selection, including when inherited from a parent optgroup; it does not prevent programmatic changes. In the example, the displayed label is Medium, while the value is m.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Option example</title>
<label for="size">Size</label>
<select id="size" name="size">
  <option value="s">Small</option>
  <option value="m" selected>Medium</option>
  <option value="l" disabled>Large</option>
</select>
<pre id="result"></pre>
<script>
  const select = document.getElementById('size');
  const option = select.options[1];
  document.getElementById('result').textContent =
    `${select.value}\n${option.text}\n${option.selected}\n${option.defaultSelected}`;
</script>
</html>

Result

m
Medium
true
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources