Switch

Toggle switch for turning settings on or off, with an optional label, a supporting description linked for screen readers, and a configurable label position.

import { Switch } from "@plexui/vue/components/Switch";

On Phone, put switches in labelled rows with a trailing control. Use compact previews to compare controls, and the settings screen to see them in context.

Examples

Overview

color

Enabled

Disabled

Label and description

Sent on Mondays.

Controlled state

Grouped settings

Preferences

Notifications

A few emails a month.

Privacy

Required for your account.

API

PropTypeDefaultDescription
checked / v-model:checkedboolean—Controlled state
default-checkedboolean—Initial state (uncontrolled)
labelstring—Accessible label rendered next to the switch
label slotVNode[]—Rich label content; takes precedence over the label prop
descriptionstring—Secondary text below the label, linked via aria-describedby
description slotVNode[]—Rich description content; takes precedence over the description prop
label-position"start" | "end""end"Label on the left (start) or right (end)
color"primary" | "accent""primary"Checked track color. Accent reads --switch-accent-color, with platform green as its fallback. Disabled checked controls retain a muted accent.
disabledbooleanfalsePrevent interaction
requiredboolean—Required for form submission
namestring—Form field name
valuestring"on"Value when submitted
classstring—CSS classes applied to the wrapper node
idstring—The id of the switch element (generated when omitted)
@update:checked(next: boolean) => void—Emitted with the next state when toggled
@focus(event: FocusEvent) => void—Emitted when the switch gains focus
@blur(event: FocusEvent) => void—Emitted when the switch loses focus

Other attributes and listeners land on the switch <button>. Built on Reka UI Switch. Inside a <form>, a hidden native checkbox mirrors the state so the value is submitted with the form.

Styling

Set --switch-accent-color once in your application's theme stylesheet for every color="accent" switch. The shared application accent recipe connects this token to primary actions and other form controls. The default color="primary" is unchanged.

The Overview includes all four states:

StateTrack and thumbInteraction
Enabled, offNeutral track; thumb at the startCan toggle
Enabled, onAccent track; thumb at the endCan toggle
Disabled, offNeutral disabled track; thumb at the start without a shadowCannot toggle
Disabled, onMuted accent track; thumb at the end without a shadowCannot toggle

On a phone the switch takes the measures of a native iOS 27.2 switch: a 63 × 28px track with a 37 × 24px thumb 2px in from its end, and an off track in the tertiary label color. The thumb casts no shadow, as the native one, a disabled switch keeps its enabled colors at half opacity, and while it is held the thumb turns into a clear lens of glass over the track.

Switch reads these component tokens. Override them at any scope to restyle it:

  • --field-label-font-weight: label font weight (default var(--font-weight-medium))
  • --switch-label-gap: label gap (default spacing(2))
  • --switch-thumb-color: thumb color (default light-dark(var(--gray-0), var(--gray-1000)))
  • --switch-thumb-color-disabled: thumb color disabled (default light-dark(var(--gray-0), var(--gray-800)))
  • --switch-thumb-offset: thumb offset (default 3px)
  • --switch-thumb-shadow: thumb shadow (default 0 1px 2px rgb(0 0 0 / 20%); on a phone none)
  • --switch-thumb-size: thumb size
  • --switch-accent-color: checked track color when color="accent" (default light-dark(#34c759, #30d158))
  • --switch-track-color: track color (default light-dark(var(--gray-150), var(--gray-400)); on a phone with touch.css the tertiary label --mobile-label-tertiary, falling back to --alpha-25: the native off track)
  • --switch-track-color-checked: track color checked (default light-dark(var(--gray-900), var(--blue-400)))
  • --switch-track-color-checked-disabled: track color checked disabled (default light-dark(var(--gray-300), var(--blue-700)); a phone dims the enabled colors instead)
  • --switch-track-color-disabled: track color disabled (default light-dark(var(--gray-100), var(--gray-300)); a phone dims the enabled colors instead)
  • --switch-track-color-hover: track color hover (default light-dark(var(--gray-200), var(--gray-450)); on a phone --alpha-30)
  • --switch-track-height: track height (default 19px)
  • --switch-track-width: track width (default 32px)