Appica UIUI 1.0.0

Switch

A toggle for turning a single setting on or off.

Usage

Switch renders only the toggle — it has no text of its own. Wrap it and its label in a single <label> so clicking either flips the switch and assistive tech announces them together; no id/htmlFor wiring needed. Use it uncontrolled with defaultChecked, or controlled with checked + onCheckedChange.

Reach for a switch when the change takes effect immediately (a setting that's on or off). For a value submitted later with a form — accepting terms, picking items — use a Checkbox instead. The thumb slide and check animation are skipped when the user prefers reduced motion.

Examples

Sizes

size scales the track and thumb together — sm, md (default), or lg.

States

A switch is off or on, and either state can also be disabled. Bridging aria-invalid paints the error state — useful for a required toggle that hasn't been accepted.

With a label and description

A typical settings row: a title and supporting text beside the toggle. Keeping it all inside one <label> makes the whole row a single target.

Controlled

Drive the state yourself with checked + onCheckedChange to react to every toggle.

RTL

Every Appica UI component supports right-to-left layouts out of the box. Set the dir attribute on a container (commonly your <html> element) so CSS logical properties resolve correctly, and wrap your tree in DirectionProvider so direction-aware behavior — roving focus, popup placement, and the like — follows the same direction.

The thumb slides toward the start edge instead of the end, following the resolved direction. For setup details and caveats, see the RTL guide.

API reference

Switch wraps Base UI's Switch and passes every remaining prop (ref, aria-*, and native <button> attributes) straight through. It exposes data-* state attributes (data-checked, data-unchecked, data-disabled, data-readonly, data-invalid, …) for styling — see the Base UI docs for the full surface.

Accessibility

  • Renders with role="switch". Space (or Enter) toggles it; Tab moves focus to and from it.
  • A switch needs an accessible name — wrap it in a <label> together with its text (as shown above), or give it an aria-label.
  • disabled removes the switch from the tab order and exposes data-disabled for styling; readOnly keeps it focusable but inert.
  • aria-invalid is bridged to data-invalid so the error state can be styled without a wrapping Field.
  • The thumb slide and check animation honour prefers-reduced-motion.

© 2026 Appica UI. A free component library, crafted by the Appica team.