Search

Find a component, token or page

Base · Actions

Toggle

A button that stays pressed until it is pressed again.

HTML / JSPlannedReactStableReact NativeDraftSwift (SwiftUI)PlannedGodotPlannedVueDraftSvelteDraftSolidDraft
Reviewed

Props

tsx
import { Toggle } from "@/components/ui/toggle"
import { RadioIcon } from "lucide-react"

<Toggle defaultPressed>
  <RadioIcon />
  Live tracking
</Toggle>

Overview

A toggle is a two-state button: on or off. It looks like a ghost or outline button and takes a muted fill while pressed. Use it for options that take effect immediately in the current view.

When to use

  • To turn a view option on or off in a toolbar, such as bold text, live tracking or a map layer.
  • When the control sits among buttons and should match their height and shape.
  • When the change applies at once and does not need a Save step.

When not to use

  • For a setting in a form or settings page: use a Switch, which reads more clearly as on/off.
  • To pick one option from a set: use a Toggle group or Radio group.
  • For an action that runs once and has no pressed state: use a Button.

Anatomy

  1. Container

    The pressable surface. Transparent at rest; the outline variant adds a border.

  2. Icon (optional)

    A 16px icon before or after the label. An icon-only toggle needs an accessible name.

  3. Label

    A short noun or verb naming the option. It must not change between on and off.

Props

The contract every language implements. Names follow each language’s conventions (camelCase in React, snake_case in Rust).

PropTypeDefaultDescription
variant"default" | "outline"defaultDefault is borderless; outline adds an input-colored border.
size"sm" | "default" | "lg"defaultControl height: 28, 32 or 36px.
disabledbooleanfalsePrevents interaction and dims the toggle.
labelstringLive trackingThe toggle text. Passed as children.
pressedboolean–Controlled pressed state. Use defaultPressed for uncontrolled.
onPressedChangefunction–Called with the new pressed state when the user toggles.

States

Off
Transparent background.
On
Muted background; aria-pressed is true.
Hover
Muted background and default text color. Pointer devices only.
Focus-visible
3px focus ring, shown for keyboard focus only.
Disabled
50% opacity and no pointer events.

Accessibility

Role: button (with aria-pressed)

KeysAction
Enter/SpaceSwitches the toggle on or off.
TabMoves focus to the next focusable element.
  • State is announced through aria-pressed, so keep the label the same in both states. Do not swap “Mute” for “Unmute”.
  • Icon-only toggles must have an aria-label.
  • Pressed state is shown with a fill change only, so pair it with a clear icon or label rather than relying on color.

Design tokens

Change any of these in Foundations and this component follows, in every language.

Platform notes

HTML / JS
Planned
Not built in HTML / JS yet.
React
Stable
Matches the contract with no platform differences.
React Native
Draft
A Pressable that reports accessibilityState.selected. The muted pressed fill also stands in for hover while a finger is down.
Swift (SwiftUI)
Planned
Not built in Swift yet.
Godot
Planned
Not built in Godot yet.
Vue
Draft
Usage snippet only; same props and behavior as the React component.
Svelte
Draft
Usage snippet only; the Svelte snippet uses `pressed` rather than `defaultPressed`.
Solid
Draft
Usage snippet only; same props and behavior as the React component.

Related