Skip to content

Switch

Free

Turns a setting on or off at once, with no Save button. It comes in 3 sizes, with invalid, disabled, and read-only states.

  • Base UI
  • React 19
  • Tailwind CSS 4

Added Nov 8, 2026 · MIT + Commons Clause

Playground

Loading the preview

Props

Use it for a setting that takes effect at once. The value is checked. Put the Switch first inside a Label, so the full row toggles it.

The sample also uses Label. One command adds them with this item:

public-profile-switch.tsx

Switch

<span>
PropTypeDefaultDescription
rounded"default""full""full"
size"default""lg""sm""default"
classNamestring—
From Base UISwitch.RootBase UI docs
idstring—The id of the hidden input element. When nativeButton is true, the id is applied to the root element.
checkedboolean—Whether the switch is currently active. To render an uncontrolled switch, use the defaultChecked prop instead.
defaultCheckedbooleanfalseWhether the switch is initially active. To render a controlled switch, use the checked prop instead.
...props<span> attributes—Every other attribute goes to the <span>, with a ref.
  • Use it for a setting that changes at once, with no Save button.
  • Use sm in a dense list and lg on a settings card made for touch.
  • In a form with a Save button, use a Checkbox.
SpaceTurns the switch on or off.
EnterTurns the switch on or off.

Switch is a Base UI Switch.Root: a <span> with role="switch" and aria-checked, and a hidden native input for the form. It also sets aria-readonly and aria-required.

Name it with a Label. Base UI reads the label of the hidden input and sets aria-labelledby on the switch.

The thumb place shows the state, not only the color. The focus ring shows on keyboard focus only. An invalid switch (aria-invalid) shows a red ring and outline.

The track is 32 × 18px (sm 24 × 14, lg 40 × 22). On a coarse pointer, hit-area grows the touch target to at least 44 × 44px.

On and off
indicator · 200ms · ease-panel (0.2, 0.4, 0.2, 1) · the thumb slides and the fill fades
Hover
hover · 150ms · ease-out (0, 0, 0.2, 1) · the track color
  1. AddedSwitch.
Open the release