Toggle

A two-state button that can be either on or off.

inputs
button
toggle
state

Preview

Variants

Basic toggle component.

Code

TSX
1
2
3
4
5
6
7
8
9
10
import { Toggle } from "@/components/ui/toggle"
import { Bold } from "lucide-react"

export function ToggleDemo() {
  return (
    <Toggle aria-label="Toggle bold">
      <Bold className="h-4 w-4" />
    </Toggle>
  )
}

API Reference

PropTypeDefaultDescription
pressedboolean-The controlled state of the toggle.
defaultPressedboolean-The default state when initially rendered.
onPressedChangefunction-Event handler called when the pressed state changes.
variantdefault | outlinedefaultThe visual style of the toggle.
sizesm | default | lgdefaultThe size of the toggle.