Switch

An on/off control for settings.

Base UI SwitchSource

Basic

Put Switch.Thumb in Switch.Root. When the switch is on, the track is orange.

Controlled

Pass checked and onCheckedChange to keep the state in your component.

Disabled

A disabled switch has 50% opacity. Add text-muted to the label yourself.

Usage

These are defaults, not laws. Break one when you have a good reason, or when it makes the design more cohesive or more interesting.

  • Choose the input from the number of options and what the user picks.
    ComponentUse it for
    RadioOne choice from 2 or 3 options that stay visible.
    SelectOne choice from 4 to about 10 options, or fewer options when space is tight.
    ComboboxOne or more choices from a long list, with typing to filter.
    AutocompleteFree text, with suggestions that the user can ignore.
    ChoiceboxA choice where each option needs a description, such as a plan.
    CheckboxAn on or off value in a form that the user submits.
    SwitchA setting that applies at once.
  • Put Switch.Root and its text in a <label>, so a click on the text toggles it.

API

Props that the library adds. Every part also takes all the Base UI props.

Switch.Thumb

PropTypeDefaultDescription
childrenReactNodeA raised faceThe face of the thumb. Pass children to replace it.