97.8k

Sonner

PreviousNext

An opinionated toast component for React.

About

Sonner is built and maintained by emilkowalski_.

Installation

Run the following command:

pnpm dlx shadcn@latest add sonner

Add the Toaster component

app/layout.tsx
import { Toaster } from "@/components/ui/sonner"
 
export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <head />
      <body>
        <main>{children}</main>
        <Toaster />
      </body>
    </html>
  )
}

Usage

import { toast } from "sonner"
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.

components/ui/sonner.tsx
"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 (
    <Sonner
      theme={theme as ToasterProps["theme"]}
      className="toaster group"
      icons={{
        success: <CircleCheckIcon className="size-4" />,
        info: <InfoIcon className="size-4" />,
        warning: <TriangleAlertIcon className="size-4" />,
        error: <OctagonXIcon className="size-4" />,
        loading: <Loader2Icon className="size-4 animate-spin" />,
      }}
      style={
        {
          "--normal-bg": "var(--popover)",
          "--normal-text": "var(--popover-foreground)",
          "--normal-border": "var(--border)",
          "--border-radius": "var(--radius)",
        } as React.CSSProperties
      }
      {...props}
    />
  )
}
 
export { Toaster }