Skip to content

Alerts with Action Buttons

Dark Tailwind CSS alerts with a title, description, primary and secondary actions, loading states, dismiss buttons and a restore option.

Also known as: alert with action buttons, notification alert banner, dismissible alert, alert with loading state, inline alert messages

Tailwind CSS Alerts Responsive Dark #alert #buttons #dark #notification #responsive

Alerts with Action Buttons live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A set of dark Tailwind CSS alerts where every message comes with a title, a short description and two actions: a primary button that fixes the problem and a secondary link or dismiss button. It suits admin dashboards, deployment tools and billing pages, where an alert should say what to do next.

How it works

The root is section.taa-alerts, with a heading, a data-taa-count badge and a hidden data-taa-reset button. Each alert is a div.taa-alert with role="group", labelled by its title and described by its data-taa-desc paragraph. A colored border-l-4 accent and icon tile mark the tone: rose, amber, sky or emerald. The alert is a CSS grid: icon and text side by side, with the action row dropping below on phones and moving to a third column from sm up. A close icon sits in the top-right corner.

The script initializes every .taa-alerts on DOMContentLoaded. A primary button marked data-taa-action is disabled when clicked, shows a .taa-spinner with its data-taa-busy text, and after a short simulated delay switches to "Done" and replaces the description with its data-taa-done message. Swap that timeout for a fetch() call and ignore its result after a restore. Any element with data-taa-dismiss (the close icon, "Later", "Dismiss") adds taa-leaving for a fade and slide, then hides the alert, updates the counter and reveals "Restore alerts", which brings every alert back in its original state. Each alert tracks its own timers, and restoring cancels them first, so a late action result never overwrites a restored alert.

Customization

  • data-taa-busy and data-taa-done on each data-taa-action button: set the in-progress label and the success message for that action.
  • border-rose-400, bg-rose-400/15 and bg-rose-400: change the color name on an alert to create a new tone, for example violet.
  • Replace a secondary a with a button that has data-taa-dismiss to make it close the alert instead of navigating.
  • sm:grid-cols-[auto_1fr_auto] on .taa-alert: remove it to keep the actions under the text on every screen size.
  • max-w-3xl on the inner wrapper: narrow it for a sidebar or widen it for a full-width notification center.
  • transform: translateX(12px) in .taa-alert.taa-leaving in style.css: change the direction or distance of the dismiss animation.

Use cases

  • Web app dashboards: alerts include a title, description and primary and secondary actions
  • Admin tools: action buttons show a loading state while a request runs
  • Settings pages: dismissed alerts can be brought back with a restore option
  • Billing and security notices: dismiss buttons let users clear messages they have read

Accessibility

Each alert is a labelled group, so screen readers announce its title and description when focus enters an action. The close icons carry hidden labels such as "Dismiss: Deployment failed". Running actions set aria-busy, and every result, dismissal and restore is announced through a role="status" region. After a dismissal, focus moves to the next alert (or the restore button) so keyboard users never lose their place. Primary buttons use dark text on light tones for strong contrast, all controls have visible focus outlines, and motion is removed under prefers-reduced-motion.

Usage notes

To show an alert from code, render the same markup and let the script initialize it, or remove the hidden attribute from an existing alert.

Alerts with Action Buttons 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
Alerts
License
Free for personal and commercial use

Questions about this template

Can I use the Alerts with Action Buttons 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.

Alerts with Action Buttons – free Tailwind CSS alert template
Alerts with Action Buttons · free Tailwind CSS alert template

More Alerts

Top Announcement Bar – free Pure CSS alert template

Top Announcement Bar

Dismissible gradient announcement bar fixed to the top of the page, with a tag, link, close button, Escape support and remembered dismissal.

Dismissible Alerts with Icons – free Bootstrap 5 alert template

Dismissible Alerts with Icons

Bootstrap 5 dismissible alerts with icons, headings, per-alert close buttons, dismiss all, restore and screen reader announcements.

Alerts Collection – free Tailwind CSS alert template

Alerts Collection

Tailwind CSS alerts collection with success, warning, error and info variants, icons, action links and accessible dismiss buttons.