Toggle
A two-state toggle button and a ToggleGroup for mutually exclusive selections โ ideal for toolbars and settings.
Quick Preview
Structure
Anatomy of the Toggle โ a button with pressed / unpressed binary state.
States
Click any toggle to switch its pressed state live.
Default variant โ all states
Click to toggle the pressed state
Default โ off
Not pressed
Default โ on
Pressed
Disabled โ off
Cannot toggle
Disabled โ on
Locked pressed
Outline variant โ all states
Same logic, bordered style
Outline โ off
Not pressed
Outline โ on
Pressed
Disabled โ off
Cannot toggle
Disabled โ on
Locked pressed
Sizes
Three size tokens โ sm md (default) lg.
Sizes โ sm / md / lg
All sizes shown in both variants
Small โ sm
Medium โ md
Large โ lg
Installation
// Copy Toggle.tsx to your components/ui/ folder// src/components/ui/Toggle.tsx
Usage
import { Toggle, ToggleGroup, ToggleGroupItem } from '@/components/ui/Toggle'// Standalone toggle<Toggle defaultPressed onPressedChange={(p) => console.log(p)}>Bold</Toggle>// ToggleGroup (single selection)<ToggleGroup defaultValue="left" onValueChange={(v) => setAlign(v)}><ToggleGroupItem value="left">Left</ToggleGroupItem><ToggleGroupItem value="center">Center</ToggleGroupItem><ToggleGroupItem value="right">Right</ToggleGroupItem></ToggleGroup>
Examples
Toggle Group โ Text Alignment
Outline Variant
Prompt Preview
Copy a prompt that recreates this UI
Paste this into your AI coding assistant to generate code that closely matches the reference, including color, size, shape, typography, spacing, and polish.
Copy-ready AI prompt
Starts from the current visual reference and project constraints.
Tweak only product-specific copy or data after the first generation pass.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
pressed | boolean | - | Controlled pressed state |
defaultPressed | boolean | false | Initial pressed state (uncontrolled) |
onPressedChange | (pressed: boolean) => void | - | Called when pressed state changes |
variant | "default" | "outline" | "default" | Visual style |
size | "sm" | "md" | "lg" | "md" | Size of the toggle |