Toggle
ToggleBlock automatically manages the data-state and aria-pressed HTML attributes to ensure visual feedback and screen-reader accessibility are perfectly synced.Sizes
- Use
size - to change the hit area and icon scale.
Installation
New project? Follow the installation guide to set up Tailwind CSS, shadcn, the cn helper and lucide-react, register the @algorize-ui registry once, then copy your styles from the Themes page.
Install Toggle
components/ is written into your project. Copy any snippet from a Usage tab above and it runs.
Install dependencies
Nothing beyond the shared setup — Toggle needs only the cn helper and lucide-react, which the installation guide already put in place.
Examples
Usage
Uncontrolled (Simple)
defaultPressed value.Controlled (Advanced)
Features
Customizable
Easily adapt the component's styling and behavior to fit your application's unique design system.
Accessible
Built with accessibility in mind, ensuring all users can interact with your application effectively.
Responsive
Fully responsive design that looks and works great across desktop, tablet, and mobile devices.
Performant
Optimized for maximum performance with minimal re-renders and efficient state management.
Best Practices & Guidelines
Usage Guidelines
Follow standard design principles when implementing this component. Ensure proper contrast, spacing, and context within your layout.
Props Reference
| Component | Prop | Type | Default | Description |
|---|---|---|---|---|
Toggle | pressed | boolean | undefined | The controlled pressed state of the toggle. If provided, the component
relies entirely on this value. |
Toggle | defaultPressed | boolean | false | The starting state when the component is uncontrolled. |
Toggle | onPressedChange | (pressed: boolean) => void | undefined | Event handler called when the pressed state of the toggle changes. |
Toggle | variant | "default" | "outline" | "ghost" | "default" | The visual style variant. ghost is highly recommended
when clustering multiple toggles together in a toolbar. |
Toggle | size | "sm" | "md" | "lg" | "md" | Adjusts the height, horizontal padding, and text-size of the toggle
button. |
Toggle | className | string | undefined | Standard Tailwind CSS overrides. |