Snippets Alert

Bootstrap 5 Alerts with Dismiss and Action Buttons

Dismissible success, warning and error alerts, each with a primary action and a dismiss button, plus a control to bring them back.

Bootstrap 5 No jQuery Dec 2019 2.4K views

<section class="wdw-stage">
  <div class="container" style="max-width:760px">
    <div class="mb-4"><span class="wdw-eyebrow">Alerts</span><h1 class="wdw-heading h3 mt-1 mb-0">Dismissible alerts with actions</h1></div>
    <div class="d-grid gap-3 wdw-alerts">
      <div class="alert wdw-notice wdw-notice-success wdw-card fade show d-flex gap-3 p-3 p-sm-4 mb-0" role="alert">
        <span class="wdw-icon wdw-notice-icon" aria-hidden="true"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><path d="m22 4-10 10-3-3"/></svg></span>
        <div class="flex-grow-1 min-w-0">
          <h2 class="alert-heading h6 fw-bold mb-1">Payment received</h2>
          <p class="mb-3">Your order #48213 is confirmed. A receipt is on its way to your inbox.</p>
          <div class="d-flex flex-wrap align-items-center gap-2">
            <a href="#" class="btn btn-sm btn-outline-secondary rounded-pill px-3">Continue shopping
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14M13 5l7 7-7 7"/></svg></a>
            <button type="button" class="btn btn-sm btn-link rounded-pill px-3 wdw-dismiss" data-bs-dismiss="alert">Dismiss</button>
          </div>
        </div>
      </div>
      <div class="alert wdw-notice wdw-notice-warning wdw-card fade show d-flex gap-3 p-3 p-sm-4 mb-0" role="alert">
        <span class="wdw-icon wdw-notice-icon" aria-hidden="true"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0z"/><path d="M12 9v4M12 17h.01"/></svg></span>
        <div class="flex-grow-1 min-w-0">
          <h2 class="alert-heading h6 fw-bold mb-1">Your session is about to expire</h2>
          <p class="mb-3">You will be signed out in 5 minutes. Save your work to avoid losing changes.</p>
          <div class="d-flex flex-wrap align-items-center gap-2">
            <a href="#" class="btn btn-sm btn-outline-secondary rounded-pill px-3">Stay signed in
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14M13 5l7 7-7 7"/></svg></a>
            <button type="button" class="btn btn-sm btn-link rounded-pill px-3 wdw-dismiss" data-bs-dismiss="alert">Dismiss</button>
          </div>
        </div>
      </div>
      <div class="alert wdw-notice wdw-notice-danger wdw-card fade show d-flex gap-3 p-3 p-sm-4 mb-0" role="alert">
        <span class="wdw-icon wdw-notice-icon" aria-hidden="true"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6M9 9l6 6"/></svg></span>
        <div class="flex-grow-1 min-w-0">
          <h2 class="alert-heading h6 fw-bold mb-1">We could not save your changes</h2>
          <p class="mb-3">The server did not respond. Check your connection and try again.</p>
          <div class="d-flex flex-wrap align-items-center gap-2">
            <a href="#" class="btn btn-sm btn-outline-secondary rounded-pill px-3">Try again
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14M13 5l7 7-7 7"/></svg></a>
            <button type="button" class="btn btn-sm btn-link rounded-pill px-3 wdw-dismiss" data-bs-dismiss="alert">Dismiss</button>
          </div>
        </div>
      </div>
    </div>
    <div class="text-center mt-4"><button type="button" class="btn btn-outline-primary rounded-pill d-none" id="alerts-reset">Show alerts again</button></div>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.