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 operationserror
- Red notification for errors and failureswarning
- Yellow notification for warningsinfo
- Blue notification for informational messagesloading
- 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
Prop | Type | Default | Description |
---|---|---|---|
type | 'success' | 'error' | 'warning' | 'info' | 'loading' | - | Notification type |
title | string | - | Main notification text |
message | string | - | Optional description |
showIcon | boolean | true | Whether to show the type icon |
duration | number | - | 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
- Limit Concurrent Notifications: Don't show too many at once
- Use Appropriate Durations: Balance visibility with user experience
- Cleanup Timeouts: Clear timeouts when components unmount
- Memoize Callbacks: Use
useCallback
foronClose
handlers - Virtual Scrolling: For many notifications, consider virtualization