Toast

Toasts are lightweight notifications that appear temporarily to provide feedback about an action or system event. Built on top of Sonner for animations and positioning, all toasts render using the Alert component for consistent styling.

Basic Usage

First, add the Toaster component to your app's root layout. Then use the toast function to trigger notifications.

// In your layout or app root
import { Toaster } from '@/components'

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <Toaster />
      </body>
    </html>
  )
}
// Anywhere in your app
import { toast } from '@/components'

toast('Hello!')
toast.success('Saved!', { description: 'Your changes have been saved.' })
toast.error('Error', { description: 'Something went wrong.' })

Interactive Demo

Click the buttons below to see different toast types:

Status Types

Toasts support five status types, each with a unique icon.

Success

toast.success('Success!', { description: 'Your changes have been saved.' })

Error

toast.error('Error', { description: 'Something went wrong.' })

Warning

toast.warning('Warning', { description: 'Please review before continuing.' })

Info

toast.info('Info', { description: 'Here is some useful information.' })

Default

toast('Notification', { description: 'You have a new message.' })

Variants

Toasts support four visual variants. Each variant can be combined with any status type.

Fill Variant

Solid colored background with white text.

toast.success('Success', { variant: 'fill', description: 'Success with fill variant' })
toast.error('Error', { variant: 'fill', description: 'Error with fill variant' })
toast.warning('Warning', { variant: 'fill', description: 'Warning with fill variant' })
toast.info('Info', { variant: 'fill', description: 'Info with fill variant' })
toast('Default', { variant: 'fill', description: 'Default with fill variant' })

Light Variant

Muted background with dark text and colored icon.

toast.success('Success', { variant: 'light', description: 'Success with light variant' })
toast.error('Error', { variant: 'light', description: 'Error with light variant' })
toast.warning('Warning', { variant: 'light', description: 'Warning with light variant' })
toast.info('Info', { variant: 'light', description: 'Info with light variant' })
toast('Default', { variant: 'light', description: 'Default with light variant' })

Stroke Variant (Default)

White background with a subtle border. This is the default variant for toasts.

toast.success('Success', { variant: 'stroke', description: 'Success with stroke variant' })
toast.error('Error', { variant: 'stroke', description: 'Error with stroke variant' })
toast.warning('Warning', { variant: 'stroke', description: 'Warning with stroke variant' })
toast.info('Info', { variant: 'stroke', description: 'Info with stroke variant' })
toast('Default', { variant: 'stroke', description: 'Default with stroke variant' })

Dark Variant

Dark background with white text.

toast.success('Success', { variant: 'dark', description: 'Success with dark variant' })
toast.error('Error', { variant: 'dark', description: 'Error with dark variant' })
toast.warning('Warning', { variant: 'dark', description: 'Warning with dark variant' })
toast.info('Info', { variant: 'dark', description: 'Info with dark variant' })
toast('Default', { variant: 'dark', description: 'Default with dark variant' })

Sizes

Toasts are available in three sizes.

Small

Compact single-line toast.

toast('Small toast', { size: 'sm' })

Medium

Standard single-line toast.

toast('Medium toast', { size: 'md' })

Large (Default)

Large toast with title, description, and action support.

toast('Large Toast', { size: 'lg', description: 'Large toast with title and description.' })

With Action Button

Add an action button to let users respond to the notification:

toast('Event has been created', {
  description: 'Monday, January 3rd at 6:00pm',
  action: {
    label: 'Undo',
    onClick: () => console.log('Undo clicked')
  }
})

With Two Actions

Large toasts can have both primary and secondary actions.

toast.info('New feature available', {
  variant: 'fill',
  description: 'We\'ve added a new dashboard feature.',
  action: { label: 'Try it now', onClick: handleTry },
  secondaryAction: { label: 'Learn more', onClick: handleLearnMore }
})

Promise Toast

Automatically show loading, success, and error states for async operations:

toast.promise(saveData(), {
  loading: 'Saving...',
  success: 'Data saved successfully!',
  error: 'Failed to save data'
})

Positions

Toasts can appear in different positions on the screen:

// Per-toast position
toast('Message', { position: 'top-right' })

// Or set default position on Toaster
<Toaster position="top-center" />

Duration & Dismissing

// Custom duration (in milliseconds)
toast('Quick message', { duration: 2000 })

// Persistent toast (must be dismissed manually)
toast('Important message', { duration: Infinity })

// Dismiss a specific toast
const toastId = toast('Loading...')
toast.dismiss(toastId)

// Dismiss all toasts
toast.dismiss()

API Reference

Toaster Props

PropTypeDefaultDescription
position"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right""bottom-right"Default position for toasts
expandbooleanfalseExpand toasts by default
closeButtonbooleanfalseShow close button on all toasts
durationnumber4000Default duration in milliseconds
toastOptionsobject-Default options for all toasts

toast() Options

OptionTypeDefaultDescription
variant"fill" | "light" | "stroke" | "dark""stroke"Visual style variant
status"error" | "info" | "success" | "warning" | "default""default"Status type (set automatically by toast.success, etc.)
size"sm" | "md" | "lg""lg"Size of the toast
descriptionstring-Secondary text below the title
durationnumber4000Time in ms before auto-dismiss
positionstring-Override position for this toast
action{ label, onClick }-Primary action button
secondaryAction{ label, onClick }-Secondary action button

toast Methods

MethodDescription
toast(title, options?)Show a default toast
toast.success(title, options?)Show a success toast
toast.error(title, options?)Show an error toast
toast.warning(title, options?)Show a warning toast
toast.info(title, options?)Show an info toast
toast.promise(promise, opts)Show loading/success/error states
toast.dismiss(id?)Dismiss specific or all toasts
toast.custom(component)Render a custom component