Skip to content

Dismissible Alerts with Icons

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

Also known as: dismissible alert messages, closable notification banners, alert with close button, status message alerts

Dismissible Alerts with Icons live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

A Bootstrap 5 notification panel with four dismissible alerts (success, info, warning and danger), each with a Bootstrap Icons symbol, a heading and a close button, plus "Dismiss all" and "Restore all" controls. Use it at the top of a dashboard, an account page or an admin area to show status messages users can clear.

How it works

The root .da-panel is a light grey card that holds a header (title, the .da-count text and two buttons) and the .da-list grid. Every alert is a standard .alert.alert-dismissible.fade.show element with the extra class .da-alert and a tone modifier such as .da-alert--warning. Inside it, .da-alert__icon is a rounded tile tinted with color-mix(), .da-alert__body holds the .da-alert__title heading and the message, and a .btn-close with data-bs-dismiss="alert" lets Bootstrap's own Alert plugin fade the alert out and remove it.

The CSS turns the alerts into white cards; each modifier sets --da-tone, which colours the left border, icon and links.

The script runs on DOMContentLoaded for every .da-panel. It stores clones of the original alerts, then listens to Bootstrap's close.bs.alert event on .da-list and to closed.bs.alert on each alert (Bootstrap fires it after removing the element, so it cannot bubble). After a single dismissal it updates the counter, announces "Storage almost full dismissed. 2 remaining." in the .da-live region and moves focus to the next alert's close button. .da-dismiss-all calls bootstrap.Alert.getOrCreateInstance(alert).close() on every alert, .da-restore puts the stored clones back, and .da-empty shows "You are all caught up." when the list is empty. Without this script the close buttons still work.

Customization

  • --da-success, --da-info, --da-warning and --da-danger on .da-panel in style.css: change the accent colour of each alert type.
  • Add a new tone: create a class such as .da-alert--neutral { --da-tone: #475569; } and use it on an alert.
  • --da-radius on .da-panel: make the alert cards sharper or rounder.
  • border-left: 4px solid var(--da-tone) in .da-alert: widen the stripe or replace it with a full border.
  • The bi-* class inside .da-alert__icon: swap the icon for any Bootstrap Icons glyph.
  • Delete the .da-restore and .da-dismiss-all buttons if you only need per-alert closing; the script checks for both and keeps working without them.
  • max-width: 680px in .da-panel: let the panel fill a wider column.

Use cases

  • Dashboards: success, info, warning and danger messages sit at the top and users clear them one by one
  • Account pages: an alert about storage or sync problems can be dismissed after it is read
  • Admin areas: Dismiss all and Restore all buttons clear or bring back the whole message list
  • Accessible apps: close buttons name the alert and a live region announces how many remain

Accessibility

Each close button has its own aria-label, such as "Dismiss: Sync failed", so screen reader users know which alert they are closing. Icons are aria-hidden="true" and meaning is carried by the heading text, not colour alone. Changes are announced through the visually hidden role="status" element, and focus never drops to the page body after an alert is removed. The static alerts do not use role="alert" because they are present on page load; add it only to alerts you insert later. Focus rings use :focus-visible, and the fade transition is turned off with prefers-reduced-motion.

Usage notes

Requires Bootstrap 5 (added automatically) and Bootstrap Icons. Several .da-panel blocks can live on one page; each keeps its own counter and restore list.

Dismissible Alerts with Icons at a glance

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

Questions about this template

Can I use the Dismissible Alerts with Icons 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 Bootstrap 5 and Bootstrap Icons 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):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
Dismissible Alerts with Icons – free Bootstrap 5 alert template
Dismissible Alerts with Icons · free Bootstrap 5 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.

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.