Command Palette

Search for a command to run...

Sonner

An opinionated toast component for React with beautiful defaults.

Installation

npm install sonner

Usage

1. Add the Toaster component to your app

1 2 3 4 5 6 7 8 9 10 11 12 13 // In your layout.tsx or root component import { Toaster } from "sonner" export default function RootLayout({ children }) { return ( <html lang="en"> <body> {children} <Toaster /> </body> </html> ) }

2. Use toast function to display notifications

1 2 3 4 5 6 7 8 9 10 11 12 13 import { toast } from "sonner" import { Button } from "@/components/ui/button" export function ToastDemo() { return ( <Button variant="outline" onClick={() => toast('Event has been created')} > Show Toast </Button> ) }

Examples

Toast Types

Custom Toast Options

Toaster Customization

1 2 3 4 5 6 7 8 9 10 11 // Custom Toaster configuration <Toaster position="top-right" richColors theme="dark" closeButton toastOptions={{ duration: 3000, className: "my-toast-class", }} />

Props

toast() Function Options

PropTypeDescription
descriptionstringAdditional description text for the toast.
durationnumberDuration in milliseconds for the toast to remain visible.
iconReactNodeCustom icon to display in the toast.
action&lbrace; label: string, onClick: () => void &rbrace;Action button configuration for the toast.
cancel&lbrace; label: string, onClick?: () => void Cancel button configuration.
dismissiblebooleanWhether the toast can be dismissed by clicking.
classNamestringCustom CSS class for the toast.

Toaster Component Props

PropTypeDefaultDescription
positionstring'bottom-right'Position of toasts on the screen.
theme'light' | 'dark' | 'system''system'Color theme for the toasts.
richColorsbooleanfalseWhether to use rich colors for different toast types.
closeButtonbooleanfalseWhether to show a close button on toasts.
toastOptionsobjectDefault options for all toasts.
offsetnumber | string32Offset from the edges of the screen.
expandbooleanfalseWhether toasts expand to fill the available width.