Love This UI? Help It Grow and Reach More Developers Worldwide

Toast

A modern, customizable toast notification system with support for multiple types, positions, and animations. Features automatic dismissal, progress bars, and seamless dark mode integration.

Preview

Test Notifications

Installation

You can add this component to your project using the CLI or by manually copying the code.

npx shadcn@latest add toast.json

Basic Usage

Simple Toast Notifications

Loading...

Available Notification Types

  • success - Green notification for successful operations
  • error - Red notification for errors and failures
  • warning - Yellow notification for warnings
  • info - Blue notification for informational messages
  • loading - Gray notification with spinning animation

Advanced Usage

Toast Manager Hook

Create a custom hook for easy toast management:

Loading...

Usage with Hook

Loading...

Loading with Success Transition

For operations that show loading state and then success:

Loading...

Positioning

Available Positions

Loading...

Position Styling

Loading...

Styling & Customization

Custom Colors

Loading...

Dark Mode Support

The component automatically supports dark mode with Tailwind's dark: prefix:

Loading...

Best Practices

1. Keep Messages Concise

Loading...

2. Use Appropriate Durations

Loading...

3. Provide Context

Loading...

4. Use Icons Appropriately

Loading...

5. Handle Multiple Notifications

Loading...

Common Use Cases

Form Submissions

Loading...

File Uploads

Loading...

API Calls

Loading...

Props Reference

PropTypeDefaultDescription
type'success' | 'error' | 'warning' | 'info' | 'loading'-Notification type
titlestring-Main notification text
messagestring-Optional description
showIconbooleantrueWhether to show the type icon
durationnumber-Auto-dismiss duration in ms
onClose() => void-Callback when notification is closed

Accessibility

  • Screen Reader Support: Proper ARIA labels and roles
  • Keyboard Navigation: Close button is keyboard accessible
  • Focus Management: Maintains focus context
  • Color Contrast: Meets WCAG guidelines for text contrast
  • Motion Preferences: Respects prefers-reduced-motion

Performance Tips

  1. Limit Concurrent Notifications: Don't show too many at once
  2. Use Appropriate Durations: Balance visibility with user experience
  3. Cleanup Timeouts: Clear timeouts when components unmount
  4. Memoize Callbacks: Use useCallback for onClose handlers
  5. Virtual Scrolling: For many notifications, consider virtualization