Skip to content

Undo Snackbar Toast

Dark Tailwind CSS inbox with a bottom snackbar that offers Undo after deleting an item, with a pausable countdown bar and focus handling.

Also known as: undo snackbar, undo delete toast, snackbar notification, bottom toast with undo, delete confirmation toast

Tailwind CSS Toasts Responsive Dark #dark #list #notification #snackbar #toast #undo

Undo Snackbar Toast live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

An undo snackbar toast built with Tailwind CSS and vanilla JavaScript. Deleting a message from the dark inbox list slides a light snackbar up from the bottom of the screen with an Undo button and a shrinking countdown bar, so an accidental delete can be reversed before it becomes final. It is the "soft delete" pattern used by mail clients, task managers and admin tables.

How it works

The root is .usb-root. It holds the inbox card with the [data-usb-list] list of li.usb-item rows, an empty state [data-usb-empty], the fixed .usb-snackbar and a visually hidden role="status" region. Each row carries its subject in data-usb-label and a [data-usb-delete] button.

A click on a delete button marks the row as pending, plays the usb-leave animation and then sets hidden on it instead of removing it. The snackbar opens through data-usb-open="true", shows the subject in [data-usb-message] and starts a timer from data-usb-timeout. The .usb-timer bar shrinks with the usb-countdown keyframes. Pressing [data-usb-undo] unhides the row with a short highlight; when the timer ends, the close button is pressed, or another row is deleted, commit() removes the row from the DOM for good. Hovering or focusing the snackbar pauses both the timer and the bar.

For the preview, the row marked data-usb-deleted starts as the pending item, so the snackbar is visible on load without a countdown.

Customization

  • data-usb-timeout="5000" on .usb-root: set how many milliseconds users have to undo; the countdown bar uses the same value.
  • commit() in script.js: add your fetch() DELETE request there, so the server only deletes once the undo window has passed.
  • bg-zinc-100 and text-violet-700 on .usb-snackbar and [data-usb-undo]: change the snackbar surface and action color; bg-violet-600 on [data-usb-timer] colors the bar.
  • fixed inset-x-4 bottom-4 max-w-md on .usb-snackbar: use sm:left-6 sm:right-auto to pin it bottom-left, or absolute to keep it inside a container.
  • transform and the cubic-bezier in .usb-snackbar in style.css: adjust the slide-in distance and bounce.
  • Remove data-usb-deleted from the Daniel Okafor row to start with a full list and a hidden snackbar.

Use cases

  • Email and inbox apps: deleting a message shows a snackbar with an Undo button
  • Admin tools: a countdown bar shows how long Undo stays available
  • Task managers: the timer pauses on hover so users have time to restore an item
  • Accessible interfaces: focus handling keeps keyboard users in control after a delete

Accessibility

Each delete button has an aria-label that names the sender. After a delete, focus moves to the next row's delete button (or to Undo when the list is empty), and after Undo it returns to the restored row. The polite role="status" region announces "Message deleted. Press Undo to restore it." and "Message restored." While closed, the snackbar uses visibility: hidden, so its buttons are skipped by Tab. Escape inside the snackbar dismisses it, the timer pauses on focus so keyboard users have time to act, and all motion stops under prefers-reduced-motion.

Usage notes

The snackbar is fixed to the viewport, so use one .usb-root per page or switch it to absolute for several demos.

Undo Snackbar Toast at a glance

Framework
Tailwind CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile, dark design
Category
Toasts
License
Free for personal and commercial use

Questions about this template

Can I use the Undo Snackbar Toast code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Undo Snackbar Toast – free Tailwind CSS toast template
Undo Snackbar Toast · free Tailwind CSS toast template

More Toasts

Bootstrap Toast Stack – free Bootstrap 5 toast template

Bootstrap Toast Stack

Bootstrap 5 toast notifications in a corner stack: success, info, warning and error buttons, selectable corner, auto-hide with a progress bar and a stack limit.

Toast with Progress Bar – free Pure CSS toast template

Toast with Progress Bar

Stacked toast notifications with a CSS countdown progress bar that pauses on hover or focus and closes the toast when it runs out.

Toast Notifications – free Tailwind CSS toast template

Toast Notifications

Stacking Tailwind CSS toast notifications for success, error and info with auto-dismiss countdown, pause on hover and accessible live region.