Toggle
The pressed surface pops in, and in a group one hover highlight glides between toggles.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/toggleThis adds components/keyframery/toggle.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.
Usage
import { Toggle } from "@/components/keyframery/toggle"
export default function Usage() {
return <Toggle aria-label="Bold">B</Toggle>
}Examples
On and off
A button that stays pressed. ToggleIcon animates the icon as it turns on.
Group
ToggleGroup with multiple for formatting. Without it, one at a time, like alignment.
Motion
| Move | What you see |
|---|---|
| Pop | The pressed surface pops in and shrinks away on release. |
| Glide | In a group, one hover highlight glides between toggles. |
| Press | Toggles press in. |
Timing and springiness follow the motion style you set. To change how fast this toggle moves, pass speed:
<Toggle speed="fast">
…
</Toggle>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--toggle-track | Group well and standalone pressed fill | --muted |
--toggle-key | Pressed key in a group | --background; --accent in dark |
--toggle-ink | Toggle text | --muted-foreground; --foreground when hovered or pressed |
--toggle-radius | Toggle corners | 8px small; 9px medium |
--toggle-group-radius | Group corners | 12px |
--toggle-gap | Space between grouped toggles | 0.125rem |
--toggle-height | Toggle height and icon width | 1.75rem small; 2rem medium |
API reference
Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK toggle reference.
Toggle
Renders a <button>, and takes its props too.
Prop
Type
ToggleGroup
Renders a <div>, and takes its props too.
Prop
Type
ToggleIcon
Renders a <span>, and takes its props too.
Prop
Type
Keyboard
| Key | What it does |
|---|---|
| Space | Turns it on or off. |
| Enter | Turns it on or off. |
| ← → | Moves between toggles in a group. |
Accessibility
Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.
Swap the import
Already using UI SDK's toggle with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.
// Before
import { … } from "@ui-sdk/react/toggle"
// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/toggle"Questions
How does the animated Toggle for UI SDK move?
Pop: The pressed surface pops in and shrinks away on release. Glide: In a group, one hover highlight glides between toggles. Press: Toggles press in.
Do I need Motion or Framer Motion for the animated Toggle?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
Can I keep my own styling and only take the motion?
Yes. Import from @/components/keyframery/primitives/toggle instead. It has the same parts and props as @ui-sdk/react/toggle and adds motion only.
What happens to the Toggle when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.