Skip to content

Sonner

Stacked toast notifications for save confirmations, uploads, and undo windows — with the neobrutalist borders-and-shadows treatment.

"use client"

import { toast } from "sonner"

Sonner puts stacked, auto-dismissing toasts on screen from a single toast() call — mount one <Toaster /> and fire notifications from anywhere, no context wiring. This is not a Radix or Base UI primitive: both backend variants wrap the same Sonner library by emilkowalski, styled to the neobrutalist recipe: thick borders, hard shadows, and bold type.

Reach for it when:

  • Action feedback — "Saved", "Copied to clipboard", "Settings updated" after a mutation resolves.
  • Async operationstoast.promise() tracks an upload or deploy from loading to success or error in one toast.
  • Undo windows — deletes and archives with an action button, so destructive operations get a grace period.

Installation

Run the following command:

pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/sonner.json
npx shadcn@latest add https://neobrutalism.com/r/base/sonner.json
yarn dlx shadcn@latest add https://neobrutalism.com/r/base/sonner.json
bunx --bun shadcn@latest add https://neobrutalism.com/r/base/sonner.json

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>
  )
}

Install the following dependencies:

pnpm add sonner next-themes
npm install sonner next-themes
yarn add sonner next-themes
bun add sonner next-themes

Copy and paste the following code into your project.

components/ui/sonner.tsx
"use client"

import {
  CircleCheckIcon,
  InfoIcon,
  Loader2Icon,
  OctagonXIcon,
  TriangleAlertIcon,
} from "lucide-react"
import { useTheme } from "next-themes"
import { Toaster as Sonner, type 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" />,
      }}
      toastOptions={{
        // Fully unstyled so the neobrutalist recipe below owns every surface:
        // hard offset shadow, 2px border, square corners, press-down buttons.
        unstyled: true,
        classNames: {
          toast:
            "group/toast relative flex w-(--width) items-center gap-3 rounded border-2 border-border bg-popover p-4 font-sans text-popover-foreground shadow-md",
          content: "flex min-w-0 flex-col gap-0.5",
          title: "font-head text-sm font-medium",
          description: "text-sm text-muted-foreground",
          icon: "shrink-0",
          actionButton:
            "ms-auto h-fit min-w-fit shrink-0 rounded border-2 border-border bg-primary px-2 py-1 text-xs font-medium text-primary-foreground shadow-sm transition-all duration-200 hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none",
          cancelButton:
            "ms-auto h-fit min-w-fit shrink-0 rounded border-2 border-border bg-muted px-2 py-1 text-xs font-medium text-foreground shadow-sm transition-all duration-200 hover:translate-x-0.5 hover:translate-y-0.5 hover:shadow-none",
          closeButton:
            "absolute -top-2 -start-2 rounded-full border-2 border-border bg-background p-0.5 transition-colors hover:bg-muted",
          success: "[&_[data-icon]]:text-chart-2",
          warning: "[&_[data-icon]]:text-chart-1",
          error: "[&_[data-icon]]:text-destructive",
        },
      }}
      {...props}
    />
  )
}

export { Toaster }

Add the Toaster component.

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

Usage

import { toast } from "sonner"
toast("Event has been created.")

Examples

Types

"use client"

import { toast } from "sonner"

Description

"use client"

import { toast } from "sonner"

Position

Use the position prop to change the position of the toast.

"use client"

import { toast } from "sonner"

Accessibility

There is no dedicated WAI-ARIA APG pattern for toasts; the closest guidance is the Alert pattern. Sonner renders toasts into a polite ARIA live region, so screen readers announce them without stealing focus. The region sits outside the normal tab order — reachable only via the hotkey — and dismiss timers pause while the stack is hovered, focused, or the tab is hidden.

Keyboard interactions:

KeyAction
Alt + TFocus and expand the toast stack (configurable via the hotkey prop on Toaster)
Tab / Shift + TabMove through toasts and their action / close buttons
Enter / SpaceActivate the focused action or close button
EscapeCollapse the toast stack while focus is inside it

API Reference

See the Sonner API Reference for more information.