Skip to content

Alerts Collection

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

Also known as: alert boxes, alert messages, notification banner, inline alerts, message boxes

Alerts Collection live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A collection of four Tailwind CSS alerts (success, warning, error and info) with solid round icons, soft tinted backgrounds and dismiss buttons. Drop them into dashboards, settings pages and forms to confirm actions, warn about limits, list validation errors or announce upcoming events.

How it works

The root is the .tac-alerts section. Each message is a .tac-alert flex row with three parts: a colored icon circle, a text column with an h3 title and body, and a close button marked data-tac-dismiss. Every alert uses one Tailwind color family from top to bottom (emerald, amber, rose and sky) for the border, background, icon and text, so recoloring is a single find and replace. The error alert shows a bulleted list of problems, the warning alert includes an inline link and the info alert has two action links.

The script initializes every .tac-alerts on DOMContentLoaded. Clicking a dismiss button adds .tac-leaving, which style.css animates with an opacity and transform transition, then sets the hidden attribute after 200 ms. The data-tac-reset button ("Show all alerts") appears as soon as one alert is dismissed and restores them all. Without JavaScript the alerts stay visible and fully readable; only dismissing is unavailable.

Customization

  • Swap the color family in one alert, for example every emerald class to teal, to change its tone without touching the others.
  • rounded-2xl on .tac-alert: use rounded-md for a sharper look, or add border-l-4 for a classic accent bar.
  • bg-emerald-600 (and siblings) on the icon circle: replace with bg-white text-emerald-600 ring-1 ring-emerald-200 for an outlined icon.
  • Delete the data-tac-dismiss button from an alert that must stay visible, such as a blocking error.
  • Remove the data-tac-reset button if you do not need to bring dismissed alerts back.
  • The 200 ms delay in script.js should match the transition duration on .tac-alert in style.css if you slow the exit down.

Use cases

  • Dashboards: confirm actions with a success alert and a dismiss button
  • Settings pages: warn about plan limits using the warning variant
  • Forms: list validation errors in an error alert with action links
  • Announcements: an info alert tells users about upcoming events

Accessibility

Each alert has role="group" with aria-labelledby pointing at its title, so screen reader users hear what the block is about. Icons are decorative and hidden with aria-hidden, and the meaning is always spelled out in the title, never by color alone. Every close button has a visually hidden label such as "Dismiss: Storage almost full". After a dismissal focus moves to the next alert's close button, the previous one, or the reset button, so keyboard users never lose their place, and a visually hidden role="status" message confirms the action. Text colors use the 800 and 900 shades on 50 backgrounds for strong contrast, focus outlines are visible on all controls and the exit animation is removed under prefers-reduced-motion.

Usage notes

These alerts are static page content, so they do not use role="alert". When you insert an alert with JavaScript in response to an action (for example a failed save), add role="alert" to the error variant so it is announced immediately.

Alerts Collection at a glance

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

Questions about this template

Can I use the Alerts Collection 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 Collection – free Tailwind CSS alert template
Alerts Collection · 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.