Skip to content
Playground

Switch

Immediate on/off settings built on Base UI.

Use Switch for a setting that takes effect immediately, such as auto-save or background sync. Its label should describe the setting, not change between “on” and “off.” Use Checkbox for choices users review before submitting together.

Backed by Base UI Switch for upstream behavior and configuration. Zenos owns the public API, styling, and composition shown on this page.

Scan new assets as they are discovered.

TSX
import { Switch } from "@zentara-co/zenos-ui";

Use defaultChecked for an uncontrolled setting. Pair checked with onCheckedChange when application state owns the setting. The callback receives the next boolean state and Base UI event details; the controlled owner must update checked.

Save changes while you edit a report.

Auto-save is enabled.

required participates in native form validation and requires the switch to be checked before submission. A disabled switch cannot be changed and contributes no form value. Pass disabled to the switch itself; use Field.Root disabled to keep the surrounding label and description consistent. Keep explanatory text visible when policy or permissions make a setting unavailable.

Required for workspace administrators.

Managed by your organization.

Set name and value to include a checked switch in native FormData. An unchecked switch contributes no value, following native checkbox behavior.

Submitted value: Not submitted

Use the usual className prop to style the track and classNameThumb to style the automatically rendered thumb. No variant or color prop is needed. Use data-[checked] and data-[disabled] for state-specific classes, and keep a visible focus-visible treatment.

When changing dimensions, update the thumb size and checked translation together so it stays inside the track. The example below uses a 52px-wide track with a 2px border, a 24px thumb, and a 24px checked translation. Include matching dark: overrides when replacing built-in dark-theme colors.

Keep your workspace up to date.

Switch and Switch.Root share the same behavior and render a default thumb when no children are supplied. To style the thumb directly or compose its contents, provide Switch.Thumb explicitly. Children replace the automatic thumb; classNameThumb no longer applies, so use className on the explicit thumb instead.

Both parts preserve Base UI state attributes, native props, and refs. Keep Switch.Thumb in the composition so checked-state movement and styling continue to work.

Show more items in each list.

Switch
Switch.Root
Switch.Thumb

API

PropTypeDefaultDescription
checked boolean — Controlled checked state.
defaultChecked boolean false Initial uncontrolled checked state.
onCheckedChange (checked: boolean, eventDetails) => void — Runs when state changes.
disabled / required boolean false Native form semantics.
name / value string — Form submission metadata.
className string — Custom track styling. Override checked and disabled states with their data attributes, and preserve a visible focus treatment.
classNameThumb string — Classes applied to the automatically rendered thumb.
children ReactNode — Replaces the automatic thumb. Render Switch.Thumb explicitly to preserve its state attributes and movement. classNameThumb only applies to the automatic thumb.
native props React.Base UI Switch props — Forwards native attributes, events, aria-*, data-*, className, style, and ref.

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

Associate every switch with a visible label using matching id and htmlFor values. Use aria-label when the surrounding visual context already explains the setting. Tab moves focus to the switch and Space toggles it; preserve this behavior when customizing its appearance.

Base UI exposes the current state through role="switch" and aria-checked; disabled and required semantics are preserved through its native form control. Keep the label stable, make both checked states visually distinguishable, and do not rely on track color alone. Preserve thumb movement and a visible keyboard focus indicator.