option
Defines an item in a select dropdown or datalist autocomplete. Each option represents a choice the user can select.
When to Use
Basic Usage
Options have a value (submitted to server) and display text (shown to user).
Code
Attributes
| Attribute | Purpose | Notes |
|---|---|---|
value |
Value sent to server on form submission | Defaults to element text content if omitted |
selected |
Pre-selects this option | Boolean attribute |
disabled |
Makes option unselectable | Shown but grayed out |
label |
Alternative display text | Used in datalist for additional context |
Placeholder Option
Use an empty value with disabled and selected for placeholder text.
Code
Pre-selected Option
Use selected to set an initial value.
Code
Disabled Options
Disable specific options that shouldn't be selectable.
Code
Value vs Display Text
The value attribute is what gets submitted; the text content is what users see.
Submitted value will be country code (US, CA, etc.)
Code
Within Option Groups
Options can be organized into optgroup categories.
In Datalist
Options in datalist provide autocomplete suggestions. The label attribute can add context.
Code
Multiple Selection
In a multiple select, users can choose several options.
Hold Ctrl/Cmd to select multiple
Code
Accessibility Notes
- Descriptive text: Option text should clearly describe the choice
- Logical order: Order options in a logical sequence (alphabetical, numerical, etc.)
- Placeholder pattern: Use disabled first option for "Select..." prompts
- Screen reader support: Options are read with their position in the list
- Keyboard navigation: Arrow keys move through options, type to jump to matching text
CSS Styling Limitations
Options have very limited CSS styling possibilities due to browser rendering.
- Cannot style individual option backgrounds or text colors reliably
- Cannot add icons or images to options
- Font styling may work but varies by browser
- For fully custom dropdowns, consider JavaScript solutions