--- title: Sonner description: An opinionated toast component for React. component: true links: doc: https://sonner.emilkowal.ski --- ## About Sonner is built and maintained by [emilkowalski](https://twitter.com/emilkowalski). ## Installation CLI Manual Run the following command: ```bash npx shadcn@latest add sonner ``` Add the Toaster component ```tsx title="app/layout.tsx" {1,9} import { Toaster } from "@/components/ui/sonner" export default function RootLayout({ children }) { return (
{children}
) } ```
Install the following dependencies: ```bash npm install sonner next-themes ``` Copy and paste the following code into your project. Add the Toaster component ```tsx showLineNumbers title="app/layout.tsx" {1,8} import { Toaster } from "@/components/ui/sonner" export default function RootLayout({ children }) { return (
{children}
) } ```
## Usage ```tsx import { toast } from "sonner" ``` ```tsx toast("Event has been created.") ``` ## Examples ## Changelog ### 2025-10-13 Icons We've updated the Sonner component to use icons from `lucide`. Update your `sonner.tsx` file to use the new icons. ```tsx showLineNumbers title="components/ui/sonner.tsx" {3-9,20-26} "use client" import { CircleCheckIcon, InfoIcon, Loader2Icon, OctagonXIcon, TriangleAlertIcon, } from "lucide-react" import { useTheme } from "next-themes" import { Toaster as Sonner, ToasterProps } from "sonner" const Toaster = ({ ...props }: ToasterProps) => { const { theme = "system" } = useTheme() return ( , info: , warning: , error: , loading: , }} style={ { "--normal-bg": "var(--popover)", "--normal-text": "var(--popover-foreground)", "--normal-border": "var(--border)", "--border-radius": "var(--radius)", } as React.CSSProperties } {...props} /> ) } export { Toaster } ```