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-busyanddata-taa-doneon eachdata-taa-actionbutton: set the in-progress label and the success message for that action.border-rose-400,bg-rose-400/15andbg-rose-400: change the color name on an alert to create a new tone, for exampleviolet.- Replace a secondary
awith abuttonthat hasdata-taa-dismissto 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-3xlon the inner wrapper: narrow it for a sidebar or widen it for a full-width notification center.transform: translateX(12px)in.taa-alert.taa-leavinginstyle.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.