Skip to content

Select - Elements ​

A select is a form input component that lets users choose one option from a predefined list.

AndroidreleasedElementsreleasediOSreleasedReactreleasedVuereleased

Accessibility ​

If a visible label isn't specified, an aria-label must be provided to the text field for accessibility. If the field is labeled by a separate element, an aria-labelledby property must be provided using the id of the labeling element instead.

Usage ​

html
<w-select label="Berries">
    <option value="raspberries">Raspberries</option>
    <option value="strawberries">Strawberries</option>
    <option value="cloudberries">Cloudberries</option>
</w-select>

Validation ​

Set the invalid attribute to display a textfield as invalid.

invalid should be paired with help-text to provide feedback to the user about how to correct the error.

html
<w-select label="Berries" invalid help-text="Select a red berry">
    <option value="raspberries">Raspberries</option>
    <option value="strawberries">Strawberries</option>
    <option value="cloudberries" selected>Cloudberries</option>
</w-select>

Examples ​

html
<w-select label="Berries">
    <option value="raspberries">Raspberries</option>
    <option value="strawberries">Strawberries</option>
    <option value="cloudberries">Cloudberries</option>
</w-select>

Placeholder ​

A select doesn't have a placeholder as such, but an <option> with an empty value gives a similar result.

html
<w-select label="Berries">
    <option value="">Select an option</option>
    <option value="raspberries">Raspberries</option>
    <option value="strawberries">Strawberries</option>
    <option value="cloudberries">Cloudberries</option>
</w-select>

Optional ​

Add the optional prop to indicate that the select is not required. To make the select optional you must add an <option> with an empty value.

html
<w-select label="Berries" optional>
    <option value="">Select an option</option>
    <option value="raspberries">Raspberries</option>
    <option value="strawberries">Strawberries</option>
    <option value="cloudberries">Cloudberries</option>
</w-select>

Help text ​

Use help-text to give additional context when the label and options are not enough.

html
<w-select label="Berries" help-text="We assume this is your jam">
    <option value="raspberries">Raspberries</option>
    <option value="strawberries">Strawberries</option>
    <option value="cloudberries">Cloudberries</option>
</w-select>

No visual label ​

You must set either an aria-label or an aria-labelledby.

html
<w-select aria-label="Berries">
    <option value="raspberries">Raspberries</option>
    <option value="strawberries" selected>Strawberries</option>
    <option value="cloudberries">Cloudberries</option>
</w-select>

Disabled ​

Keep in mind that using disabled is an anti-pattern.

There will always be users who don't understand why an element is disabled, or users who can't even see that it is disabled because of poor lighting conditions or other reasons.

Please consider more informative alternatives before choosing to use disabled on an element.

html
<w-select label="Berries" disabled>
    <option value="raspberries">Raspberries</option>
    <option value="strawberries">Strawberries</option>
    <option value="cloudberries">Cloudberries</option>
</w-select>

Read only ​

The readonly boolean attribute makes the selection immutable. Unlike disabled the select remains focusable. See MDN docs for more information.

html
<w-select label="Berries" readonly>
    <option value="raspberries">Raspberries</option>
    <option value="strawberries">Strawberries</option>
    <option value="cloudberries">Cloudberries</option>
</w-select>

Styling API ​

This section documents the supported styling hooks for <w-select>.

Use these hooks to customize appearance without relying on internal structure or selectors.

Before changing the default styles, remember that doing so can result in less consistent experiences for users across the product. Prefer defaults.

  • Prefer component tokens for size, spacing, and state styling.
  • Use parts only for small, local tweaks.
  • Avoid relying on internal class names or selectors.

Parts ​

The select exposes a minimal set of parts that can be targeted for last‑mile layout or typography tweaks.

PartTargetsTypical use
inputnative select elementminor typography or spacing tweaks

Example:

css
w-select::part(input) {
  letter-spacing: 0.5px;
}

Parts are intended as an escape hatch. Prefer component tokens for anything state‑ or size‑related.

Component tokens ​

Component tokens (--w-c-input-*) act as inputs to the select styling. They can be set directly on the component or inherited from a parent container.

These tokens are shared across textfield, textarea, and select for consistent form styling.

css
.form-section {
  --w-c-input-label-font-weight: 600;
  --w-c-input-help-text-color: var(--w-s-color-text);
}

Defaults are defined internally; setting a token is always optional.

Label tokens ​

TokenPurposeDefault
--w-c-input-label-colorlabel text color--w-s-color-text
--w-c-input-label-font-sizelabel font size--w-font-size-s
--w-c-input-label-line-heightlabel line height--w-line-height-s
--w-c-input-label-font-weightlabel font weight700
--w-c-input-label-padding-bottomspace below label0.4rem
--w-c-input-label-cursorcursor when hovering labelpointer
--w-c-input-label-displaylabel display modeblock

Optional indicator tokens ​

When optional attribute is set, these tokens control the "(optional)" text styling:

TokenPurposeDefault
--w-c-input-optional-coloroptional text color--w-s-color-text-subtle
--w-c-input-optional-font-sizeoptional text font size--w-font-size-s
--w-c-input-optional-line-heightoptional text line height--w-line-height-s
--w-c-input-optional-font-weightoptional text font weight400
--w-c-input-optional-padding-leftspace before optional text0.8rem

Help text tokens ​

TokenPurposeDefault
--w-c-input-help-text-colorhelp text color (normal state)--w-s-color-text-subtle
--w-c-input-help-text-color-invalidhelp text color when invalid--w-s-color-text-negative
--w-c-input-help-text-font-sizehelp text font size--w-font-size-xs
--w-c-input-help-text-line-heighthelp text line height--w-line-height-xs
--w-c-input-help-text-margin-topspace above help text0.4rem
--w-c-input-help-text-displayhelp text display modeblock

Implementation notes ​

Shared token system ​

Select shares its label, optional indicator, and help text tokens with w-textfield and w-textarea. This ensures consistent form styling across all text input components.

<w-select> API ​

Unless otherwise noted all properties are HTML attributes (as opposed to JavaScript object properties).

Properties ​

NameTypeDefaultSummary
alwaysbooleanfalseWhether to always show a hint. Deprecated: Use help-text instead and only set it if you want to display the help text.
auto-focusbooleanfalseWhether the element should receive focus on render. Deprecated: Use the native autofocus attribute instead.
autofocusbooleanfalseWhether the element should receive focus on render
disabledbooleanfalseRenders the field in a disabled state.
help-textstring | undefined-The content displayed as the help text.
hintstring | undefined-The content displayed as the help text. Deprecated: Use help-text instead.
invalidbooleanfalseRenders the field in an invalid state.
labelstring | undefined-The content to display as the label.
namestring | undefined-The name of the select when submitting the form.
optionalbooleanfalseWhether to show the optional indicator after the label.
read-onlybooleanfalseRenders the field in a readonly state. Deprecated: Use the native readonly attribute instead.
readonlybooleanfalseRenders the field in a readonly state.
valuestring | undefined-Lets you set the current value.

Property Details ​

always ​

Deprecated: Use help-text instead and only set it if you want to display the help text.

Whether to always show a hint.

  • Type: boolean
  • Default: false

auto-focus ​

Deprecated: Use the native autofocus attribute instead.

Whether the element should receive focus on render.

  • Type: boolean
  • Default: false

autofocus ​

Whether the element should receive focus on render

  • Type: boolean
  • Default: false

disabled ​

Renders the field in a disabled state.

  • Type: boolean
  • Default: false

help-text ​

The content displayed as the help text.

Paired with invalid to show the text as a validation error.

  • Type: string | undefined
  • Default: -

hint ​

Deprecated: Use help-text instead.

The content displayed as the help text.

  • Type: string | undefined
  • Default: -

invalid ​

Renders the field in an invalid state.

Paired with help-text to provide feedback about the error.

  • Type: boolean
  • Default: false

label ​

The content to display as the label.

  • Type: string | undefined
  • Default: -

name ​

The name of the select when submitting the form.

  • Type: string | undefined
  • Default: -

optional ​

Whether to show the optional indicator after the label.

  • Type: boolean
  • Default: false

read-only ​

Deprecated: Use the native readonly attribute instead.

Renders the field in a readonly state.

  • Type: boolean
  • Default: false

readonly ​

Renders the field in a readonly state.

  • Type: boolean
  • Default: false

value ​

Lets you set the current value.

  • Type: string | undefined
  • Default: -

Events ​

change ​

  • Type: CustomEvent

Questions? ​

Feel free to ask any questions on usage in the Warp DS Slack channel: #warp-design-system