Skip to content

Alerts with Icons

Bootstrap 6 alerts in every theme color with solid icon tiles, headings, actions, a storage meter, dismiss buttons with focus handling and a restore control.

Also known as: alert with icon, icon alert messages, notification alert boxes, status message alerts

Alerts with Icons live demo

Open in new tab

Bootstrap 6 code (HTML, CSS, JS)

A set of Bootstrap 6 alerts with icons for dashboards, settings pages and app shells. It covers info, success, warning and danger messages, a rich welcome alert with actions, a "new feature" alert and a compact dark offline banner. Each alert has a solid icon tile in its theme color, a colored edge and a dismiss button.

How it works

Every alert is a plain Bootstrap 6 .alert with a theme-* class: theme-info, theme-success, theme-warning, theme-danger, theme-primary, theme-accent and theme-inverse. The theme class sets --bs-theme-bg, --bs-theme-fg and related variables, and .awi-alert reuses them. The left edge uses border-inline-start-color: var(--bs-theme-bg) and the .awi-icon tile uses the same color as its background with --bs-theme-contrast for the Bootstrap Icon. So one class change recolors the whole alert.

The warning alert holds a small .progress meter, the rich alert adds an .alert-heading and two buttons, and .awi-alert-compact turns the inverse alert into a solid dark banner.

Dismissing needs no code: each .btn-close has data-bs-dismiss="alert", and the bundle fades the alert out and removes it. The script listens for close.bs.alert on .awi-root to remember the alert and choose where focus should go. Bootstrap fires closed.bs.alert after the alert has left the page, so that listener is added to the alert itself. Focus then moves to the next dismiss button or to the restore button instead of falling back to the page body. .awi-restore (demo only) puts hidden alerts back in their original order using data-awi-index.

Customization

  • Change theme-warning (or any theme-* class) on an .alert to recolor its background, text, edge and icon tile at once.
  • --awi-icon-size on .awi-root: makes the icon tiles larger or smaller; .awi-icon-lg is the bigger variant used in the rich alert.
  • --awi-stripe on .awi-root: sets the width of the colored left edge. Use 0 for a plain border.
  • --awi-radius on .awi-root: rounds the alert corners.
  • Swap the bi-* class inside .awi-icon for any Bootstrap Icon.
  • width on .awi-meter-bar and aria-valuenow on .awi-meter: show a different storage level.
  • Replace the setTimeout in the .awi-retry click handler with a real connectivity check such as fetch('/ping').

Use cases

  • Admin dashboards: show info, success, warning and danger messages with colored icon tiles and dismiss buttons
  • Settings pages: warn about storage limits using an alert that includes a small usage meter
  • App welcome screens: greet new users with a rich alert holding a heading and two action buttons
  • Offline or connection notices: display a compact dark banner with a retry button when the network drops

Accessibility

Warnings and errors use role="alert" so screen readers announce them immediately; informational messages use the politer role="status". Icons are decorative (aria-hidden="true"), so the bold lead-in text carries the meaning, not the color alone. Every dismiss button has a specific aria-label such as "Dismiss upload error". Bootstrap draws .btn-close with a CSS mask, which hides outlines, so keyboard focus shows it at full opacity. The storage meter is a labelled progressbar.

Bootstrap 6 notes

alert alert-danger from Bootstrap 5 is now alert theme-danger, alert-dismissible and the .fade .show classes are gone, and the close button simply sits inside the flex alert. Text goes in a <p>, and theme-accent and theme-inverse are new color roles. Built on 6.0.0-alpha.1, so names may still change. Icons come from Bootstrap Icons.

Alerts with Icons at a glance

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

Questions about this template

Can I use the 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 6 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@6.0.0-alpha.1/dist/css/bootstrap.min.css">
  • <script type="module" src="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/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">

Built for Bootstrap 6.0.0-alpha.1. Bootstrap 6 ships as an ES module, so its script and this component's JavaScript load with type="module". Alpha releases can still change before the stable version.

Alerts with Icons – free Bootstrap 6 alert template
Alerts with Icons · free Bootstrap 6 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 with Action Buttons – free Tailwind CSS alert template

Alerts with Action Buttons

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

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.