Toast Notification
Slide-in toast notification with icon and close button.
Saved successfully
Your changes are live.
<div class="max-w-sm rounded-2xl border border-slate-200 bg-white p-4 shadow-xl flex items-start gap-3">
<span class="w-8 h-8 rounded-full bg-emerald-100 text-emerald-600 flex items-center justify-center flex-shrink-0">
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/></svg>
</span>
<div class="flex-1">
<p class="text-sm font-bold text-slate-900">Saved successfully</p>
<p class="text-xs text-slate-500 mt-0.5">Your changes are live.</p>
</div>
<button aria-label="Dismiss" class="text-slate-400 hover:text-slate-600 transition-colors">
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/></svg>
</button>
</div>Free to use in personal and commercial projects. No attribution required.
Variants
Same component, different looks. Preview each one live and copy the code you like.
Error
Use the red error toast when an action fails and the user must retry.
Payment failed
Your card was declined. Try another one.
Dark
The dark toast fits dark-mode apps and admin panels.
Backup complete
All files synced to the cloud.
With action
Add the Undo action for destructive toasts like deletes and archives.
Conversation archived
You can restore it within 30 days.
About this toast notification
Toast notifications are the small popups that slide in to confirm an action: "Saved", "Message sent", "Item added to cart". Unlike alert banners that sit in the page layout, a tailwind toast notification floats above the content, usually bottom-right or top-center, and dismisses itself after a few seconds.
Every major UI library ships toasts: shadcn, Sonner, DaisyUI. They are so common because they confirm actions without interrupting flow. No modal to dismiss, no page reload, just a quick confirmation that fades away.
This copy-paste toast gives you the standard structure: icon, title, message, and dismiss button. Pair it with a tiny bit of JavaScript to show/hide it, or use it as the markup inside Sonner or your own toast system. For variants, swap emerald for red (error), amber (warning), or blue (info).
Every click needs an answer. When a user saves a form and nothing visibly happens, they click again, and now you have a duplicate order or a double post. Toast notifications close that feedback gap: they confirm the action happened while letting the user keep working. Unlike a modal, they never steal focus; unlike a page reload, they never lose context. They exist because silent interfaces make users anxious and anxious users click twice.
The structure here is the standard pattern: a max-w-sm rounded-2xl border bg-white p-4 shadow-xl container in flex with items-start and gap-3. The icon is a w-8 h-8 rounded-full badge, emerald-100 background with emerald-600 glyph and flex-shrink-0 so it never squishes. The title is text-sm font-bold, the message text-xs text-slate-500, and the dismiss button carries an aria-label so screen readers announce its purpose. Swap the emerald classes for red, amber, or blue to get error, warning, and info variants from the same markup.
Time the auto-dismiss to the message: 4 seconds for a short success, 6 to 8 for anything the user might actually need to read. Slide in with a translate-y and opacity keyframe rather than popping into existence. On mobile, keep the toast narrow and bottom-anchored so it never covers the primary action; a max-w-sm toast on a 360px screen is fine, a full-width one is a wall.
The classic mistake is letting the dismiss timer run while the user is hovering to read a longer message, so the toast vanishes mid-sentence. The fix is simple: pause the timeout on mouseenter and resume on mouseleave. A toast that disappears while being read teaches users that notifications can't be trusted, which defeats their entire purpose.
Frequently asked questions
Toast notification vs alert banner, what is the difference?
A toast floats above content and auto-dismisses, used for transient confirmations. An alert banner sits inside the page layout and stays until dismissed, used for important persistent messages.
Where should toast notifications appear?
Bottom-right is the most common on desktop, top-center on mobile. Pick one position and keep it consistent across your app.
How long should a toast stay visible?
Four to five seconds is standard. Long enough to read, short enough not to annoy. Error toasts can stay longer or require manual dismissal.
How do I stack multiple toast notifications?
Wrap toasts in a fixed container with flex column and a gap, and append new toasts to the top or bottom consistently. Cap visible toasts at 3 or 4 and queue the rest so they appear as older ones dismiss. Each toast needs its own timer so dismissals stay independent.
How do I add a slide-in animation to toast notifications?
Use a keyframe that animates from translateY(1rem) or translateX(100%) with opacity 0 to the resting position. Apply it on mount, and for exit add a class that reverses the motion before removing the element from the DOM. Keep the duration around 200 to 300ms so it feels snappy.
Should toast notifications have a progress bar?
A thin progress bar is useful when the toast auto-dismisses, because it shows how much time is left to read or act. Skip it for persistent toasts that require manual dismissal, like errors. Animate the bar with a linear width transition matching the dismiss timeout.
Where to use it
- ✓ Form submission confirmations
- ✓ Cart and checkout feedback
- ✓ Copy-to-clipboard confirmation
- ✓ Error and warning alerts
Design notes
When to use
Use it to confirm actions without interrupting flow: form submissions, cart additions, and copy-to-clipboard feedback. Floating above the content and dismissing itself, a toast says saved while the user keeps working. Bottom right or top center are the expected spots.
What to avoid
Do not use toasts for critical information that needs acknowledgment, like payment failures; those deserve a modal or a persistent banner. Do not stack many toasts at once or let them cover primary actions.
Accessibility
Use role=status for confirmations or role=alert for errors so screen readers announce them. Give a generous auto-dismiss time, keep the close button keyboard reachable, and never trap focus inside a toast.
Customization tips
Position toasts with fixed bottom-4 right-4 on the wrapper. For auto-dismiss, add a setTimeout that fades it out after 4 seconds. Stack multiple toasts with space-y-2 in a flex-col container.
Related elements
Star Rating
Interactive star rating with hover fill.
Progress Bar
Animated progress bar with striped variant.
Success. Your profile has been updated.
Warning. Your trial ends in 3 days.
Error. Payment failed. Try again.
Info. New features are available.
Alert Banner
Dismissible alert banner in 4 variants.