Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

option

Defines an item in a select dropdown or datalist autocomplete. Each option has a value submitted to the server and display text shown to the user.

When to Use

  • Inside select elements for dropdown menus
  • Inside datalist elements for autocomplete suggestions
  • Inside optgroup for categorized options

Examples

A placeholder option, a pre-selected option, a disabled option, the label attribute, and options as datalist suggestions.

Value vs Display Text

The value attribute is what gets submitted to the server. The text content between the tags is what users see in the dropdown. If value is omitted, the text content serves as both.

Attributes

Attribute Purpose Notes
value Value sent to server on form submission Defaults to element text content if omitted
selected Pre-selects this option on page load Boolean attribute
disabled Makes option visible but unselectable Shown grayed out
label Display text that replaces the element's text content In a select it is what the user sees; in a datalist browsers show it alongside (or instead of) the value

Placeholder Pattern

Make the first option a prompt with an empty value and put required on the select. HTML treats that first empty option as the select's placeholder: the select stays invalid until the user picks a real option, so the form cannot be submitted with the prompt chosen.

The prompt only counts when it is the first option, has an empty value, is not inside an optgroup, and the select is a single-row dropdown (no multiple, size of 1 or absent). Adding disabled as well stops users re-choosing the prompt once they have picked something; it is optional, as validation works either way.

Pre-selected Option

Use the selected attribute to set a default value. Without it, a single-row select starts on its first option that is not disabled; a multiple select or one with size greater than 1 starts with nothing selected.

Disabled Options

Disable specific options that should be visible but not selectable. Useful for showing unavailable choices.

In Datalist

Options in datalist provide autocomplete suggestions for text inputs. The label attribute adds descriptive context alongside the value.

Styling

Classic select

In browsers without customizable select, and in every listbox select (multiple, or size greater than 1), the option list is drawn by the browser or the operating system. VB styles the parent select; options keep the platform look.

  • Option backgrounds and text colours cannot be styled reliably
  • Icons and images inside options are not rendered
  • Font styling may work but varies by browser and OS
  • For fully custom dropdowns, see the combo-box web component

Customizable select (Chromium 135+)

Where appearance: base-select is supported, VB turns it on for single-row selects and styles the options in the picker: padded rows with rounded corners, a hover fill on options that are not disabled, the checked option in the interactive colour with a ::checkmark, and rich HTML content (images, icons) laid out with flex. The checked option's content is cloned into the selectedcontent trigger. In forced-colors mode the hovered option uses Highlight and disabled options GrayText. See the select customizable select section for details.

Accessibility

  • Descriptive text: Option text should clearly describe the choice
  • Logical order: Order options in a predictable sequence (alphabetical, numerical, by frequency)
  • Keyboard navigation: Arrow keys move through options; typing jumps to matching text
  • Screen reader support: Options are announced with their position in the list; disabled options are announced as unavailable
  • Don't rely on rich content: Images and icons in a customizable select's options are decoration. Keep the option's text meaningful on its own and mark decorative images with alt="" or aria-hidden="true"

Related

  • select - Dropdown container for options
  • optgroup - Groups related options together
  • selectedcontent - Clones selected option content into the trigger
  • datalist - Autocomplete container for options
↑