Command Palette

Search for a command to run...

Sonner

Toast notification banners with five semantic variants, automatic RTL positioning, customizable icons, and mobile-responsive layout.

Installation

pnpm dlx shadcn@latest add https://dga-registry.vercel.app/r/sonner.json

Usage

Add the <Toaster /> component to your root layout, then call the toast helpers anywhere in your app.

// app/layout.tsx
import { Toaster } from "@/components/ui/sonner"

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <Toaster />
      </body>
    </html>
  )
}
// Trigger a toast from any component
import { toastSuccess } from "@/components/ui/sonner"

toastSuccess("Changes saved successfully.", "Success")

Variants

Five semantic variants styled from DGA Figma design tokens.

VariantBackgroundText ColorUse Case
error#fef3f2#b42318Errors & failures
warning#fffaeb#b54708Warnings & caution
success#ecfdf3#067647Success confirmations
info#eff8ff#175cd3Informational notices
neutral#f9fafb#384250General-purpose messages

Without Title

Toasts can be shown with just a message — the title is optional.

showToast Shorthand

Use the showToast object for a convenient API:

import { showToast } from "@/components/ui/sonner"

showToast.error("Something went wrong.")
showToast.warning("Check your input.", "Warning")
showToast.success("Saved!", "Done")
showToast.info("Update available.")
showToast.neutral("3 pending items.")

Custom Icons

Override the default icon for any variant by passing an options object:

import { StarIcon } from "@hugeicons/core-free-icons"

import { toastInfo } from "@/components/ui/sonner"

toastInfo("You earned a gold star!", "Achievement", {
  icon: StarIcon,
  iconType: "solid",
})

Positioning

Control where toasts appear with the position prop on <Toaster />. Click a position to preview it live.

PositionDescription
top-leftTop-left corner
top-centerTop-center
top-rightTop-right corner (default)
bottom-leftBottom-left corner
bottom-centerBottom-center
bottom-rightBottom-right corner
<Toaster position="bottom-right" />
<Toaster position="top-right" />

In RTL mode, left↔right positions are auto-flipped. On mobile, position is always bottom-center.

RTL Support

The <Toaster /> automatically flips leftright positions when inside an RTL <DirectionProvider />. On mobile, toasts always appear at bottom-center.

Toaster Offset

Use <ToasterOffsetProvider> and <SetToasterOffset> to dynamically push toasts below a fixed header:

import {
  SetToasterOffset,
  Toaster,
  ToasterOffsetProvider,
} from "@/components/ui/sonner"

function Layout({ children }) {
  return (
    <ToasterOffsetProvider>
      <SetToasterOffset value={64} />
      {children}
      <Toaster />
    </ToasterOffsetProvider>
  )
}

Or use the useToasterOffset hook to measure dynamically (e.g. from a header component):

import { useEffect, useRef } from "react"

import { useToasterOffset } from "@/components/ui/sonner"

function AppHeader() {
  const headerRef = useRef<HTMLElement>(null)
  const { setOffset } = useToasterOffset()

  useEffect(() => {
    const el = headerRef.current
    if (!el) return
    const observer = new ResizeObserver(([entry]) => {
      setOffset(Math.round(entry.contentRect.height))
    })
    setOffset(el.offsetHeight)
    observer.observe(el)
    return () => {
      observer.disconnect()
      setOffset(0)
    }
  }, [setOffset])

  return <header ref={headerRef}>...</header>
}

Toaster Props

PropTypeDefaultDescription
positionPosition"top-right"Toast position (auto-flipped in RTL, bottom-center on mobile)

Toast Helper Functions

FunctionParametersDescription
toastError(message, title?, options?)Show error toast
toastWarning(message, title?, options?)Show warning toast
toastSuccess(message, title?, options?)Show success toast
toastInfo(message, title?, options?)Show info toast
toastNeutral(message, title?, options?)Show neutral toast

Toast Options

OptionTypeDefaultDescription
iconIconDefinitionVariant defaultOverride the variant icon
iconType"solid" | "stroke"Variant defaultIcon style
dismissIconIconDefinitionCancel01IconOverride the dismiss icon

Exports

ExportTypeDescription
ToasterComponentPlace in root layout
ToasterOffsetProviderComponentWrap around Toaster for offset
SetToasterOffsetComponentSet dynamic offset value
useToasterOffsetHookAccess offset context directly
toastErrorFunctionShow error toast
toastWarningFunctionShow warning toast
toastSuccessFunctionShow success toast
toastInfoFunctionShow info toast
toastNeutralFunctionShow neutral toast
showToastObjectShorthand { error, warning, ... }
PositionType"top-left" | "top-center" | ...