Skip to main content

Toggle

A pressable two-state button with tactile press compression, a morphing active surface, and a subtle content pop.

Preset
pinned=on

Customize

SizeDefault
Press scale0.95
Speed1

Installation

npx shadcn@latest add @kinetic/toggle

Usage

Import the toggle and let it manage its own pressed state:

import { Toggle } from "@/components/kinetic/ui/toggle";

export function BoldToggle() {
  return <Toggle aria-label="Toggle bold">B</Toggle>;
}

Controlled state

Pass pressed and onPressedChange to control the state, or defaultPressed to set the initial value of an uncontrolled toggle. The button exposes aria-pressed.

const [pressed, setPressed] = useState(false);

<Toggle pressed={pressed} onPressedChange={setPressed} aria-label="Toggle italic">
  I
</Toggle>

Variants and sizes

Choose variant as default or outline, and size as sm, default, or lg. An icon-only toggle needs an accessible label. Use toggleVariants to apply the same styles to a custom element.

import { Toggle, toggleVariants } from "@/components/kinetic/ui/toggle";

<Toggle variant="outline" size="sm" aria-label="Toggle underline">U</Toggle>
<Toggle size="lg" defaultPressed>Favorite</Toggle>
<a href="#filters" className={toggleVariants({ variant: "outline", size: "sm" })}>Filters</a>

Press feedback

Use pressScale to change how far the toggle compresses while pressed. The default is 0.95, and values are clamped between 0.88 and 0.99.

<Toggle pressScale={0.9}>Mute</Toggle>

Disabled

A disabled toggle ignores input and keeps its current state.

<Toggle disabled>Locked</Toggle>

Motion preferences

The active surface morph, press compression, and content pop respect the browser's reduced-motion preference and the Kinetic reduced-motion setting. Timing follows the current tempo, and speed scales it for a single toggle.

API Reference

Toggle

Zero-dependency accessible toggle button with tactile press compression, morphing active surface, and content pop.

PropTypeDefaultDescription
pressed / defaultPressed / onPressedChangeboolean / boolean / (pressed: boolean) => void-Controlled or uncontrolled pressed state.
variant / size"default" | "outline" / "sm" | "default" | "lg""default" / "default"Surface border style and height scale.
pressScale / speednumber / number0.95 / 1Press compression scale (0.88-0.99) and animation speed multiplier (0.25-4).

toggleVariants

Zero-dependency class helper returning Toggle styling for variant and size combinations.

PropTypeDefaultDescription
variant / size / className"default" | "outline" / "sm" | "default" | "lg" / string"default" / "default"Variant, size, and optional extra utility classes merged via cn().

Notes

Always add aria-label on icon-only toggles and omit size-* classes on child icons. For 2 to 7 related choices, prefer ToggleGroup.