Bootstrap 5 Alerts: Info, Success, Warning, Error
Dismissible alerts for info, success, warning and error states in a soft tinted style and an accent-bar style, with buttons that fire new alerts.
<section class="wdw-stage wdw-alerts">
<div class="container" style="max-width:1000px">
<div class="text-center mb-4">
<span class="wdw-eyebrow">Feedback</span>
<h2 class="wdw-heading h3 mb-1">Alerts & messages</h2>
<p class="wdw-muted mb-0">Soft and solid dismissible alerts, plus toast notifications you can fire.</p>
</div>
<div class="row g-4">
<div class="col-lg-6">
<div class="wdw-card p-4 d-grid gap-3 h-100 align-content-start">
<h3 class="h6 fw-bold mb-0 wdw-muted">Soft</h3>
<div class="alert alert-info soft alert-dismissible fade show d-flex align-items-start gap-3 mb-0" role="alert">
<span class="ico flex-shrink-0"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/></svg></span>
<div><strong class="d-block">Heads up</strong><span>A new version is available. Refresh to get the latest features.</span></div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-success soft alert-dismissible fade show d-flex align-items-start gap-3 mb-0" role="alert">
<span class="ico flex-shrink-0"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="m8.5 12.5 2.5 2.5 4.5-5"/></svg></span>
<div><strong class="d-block">Saved</strong><span>Your changes were published to the live site.</span></div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-warning soft alert-dismissible fade show d-flex align-items-start gap-3 mb-0" role="alert">
<span class="ico flex-shrink-0"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3 2.5 20h19L12 3Z"/><path d="M12 10v4M12 17h.01"/></svg></span>
<div><strong class="d-block">Check your plan</strong><span>You have used 90% of your monthly storage.</span></div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-danger soft alert-dismissible fade show d-flex align-items-start gap-3 mb-0" role="alert">
<span class="ico flex-shrink-0"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="m9 9 6 6M15 9l-6 6"/></svg></span>
<div><strong class="d-block">Payment failed</strong><span>Your card was declined. Update billing details to retry.</span></div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="wdw-card p-4 d-grid gap-3 h-100 align-content-start">
<h3 class="h6 fw-bold mb-0 wdw-muted">Solid with action</h3>
<div class="alert alert-info solid alert-dismissible fade show d-flex align-items-start gap-3 mb-0" role="alert">
<span class="flex-shrink-0"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/></svg></span>
<div><strong class="d-block">New comment</strong><span>Maya replied to your design review.</span> <a href="#" class="alert-link ms-1 text-white fw-semibold">Open thread</a></div>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-success solid alert-dismissible fade show d-flex align-items-start gap-3 mb-0" role="alert">
<span class="flex-shrink-0"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="m8.5 12.5 2.5 2.5 4.5-5"/></svg></span>
<div><strong class="d-block">Invite sent</strong><span>Three teammates were invited to the workspace.</span> <a href="#" class="alert-link ms-1 text-white fw-semibold">Undo</a></div>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-warning solid alert-dismissible fade show d-flex align-items-start gap-3 mb-0" role="alert">
<span class="flex-shrink-0"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 3 2.5 20h19L12 3Z"/><path d="M12 10v4M12 17h.01"/></svg></span>
<div><strong class="d-block">Trial ends soon</strong><span>Your free trial finishes in 2 days.</span> <a href="#" class="alert-link ms-1 text-white fw-semibold">Upgrade</a></div>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-danger solid alert-dismissible fade show d-flex align-items-start gap-3 mb-0" role="alert">
<span class="flex-shrink-0"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="m9 9 6 6M15 9l-6 6"/></svg></span>
<div><strong class="d-block">Upload failed</strong><span>hero-banner.png is larger than the 10 MB limit.</span> <a href="#" class="alert-link ms-1 text-white fw-semibold">Retry</a></div>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
</div>
</div>
</div>
<div class="d-flex flex-wrap justify-content-center gap-2 mt-4" id="alert-triggers">
<button type="button" class="btn btn-outline-primary rounded-pill" data-fire="info">Fire info</button>
<button type="button" class="btn btn-outline-primary rounded-pill" data-fire="success">Fire success</button>
<button type="button" class="btn btn-outline-primary rounded-pill" data-fire="warning">Fire warning</button>
<button type="button" class="btn btn-outline-primary rounded-pill" data-fire="danger">Fire danger</button>
</div>
<div class="toast-container position-fixed bottom-0 end-0 p-3" id="toast-stack"></div>
</div>
</section>
/* Web Designer Wall library style — shared base for every Bootstrap 5 snippet.
Indigo accent, Plus Jakarta Sans, soft cards, pill buttons. Works in light and dark. */
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");
:root,
[data-bs-theme="light"] {
--wdw-font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
--bs-body-font-family: var(--wdw-font);
--bs-primary: #4f46e5;
--bs-primary-rgb: 79, 70, 229;
--bs-primary-text-emphasis: #3730a3;
--bs-primary-bg-subtle: #eef2ff;
--bs-primary-border-subtle: #c7d2fe;
--bs-link-color: #4f46e5;
--bs-link-color-rgb: 79, 70, 229;
--bs-link-hover-color: #4338ca;
--bs-link-hover-color-rgb: 67, 56, 202;
--bs-focus-ring-color: rgba(79, 70, 229, 0.25);
--bs-border-radius: 0.75rem;
--bs-border-radius-lg: 1rem;
--bs-border-radius-xl: 1.25rem;
--wdw-radius-card: 1.25rem;
--wdw-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 40px -16px rgba(16, 24, 40, 0.22);
--wdw-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px -4px rgba(16, 24, 40, 0.12);
--wdw-stage: #f5f6fb;
}
[data-bs-theme="dark"] {
--bs-primary: #818cf8;
--bs-primary-rgb: 129, 140, 248;
--bs-primary-text-emphasis: #c7d2fe;
--bs-primary-bg-subtle: rgba(129, 140, 248, 0.14);
--bs-primary-border-subtle: rgba(129, 140, 248, 0.35);
--bs-link-color: #a5b4fc;
--bs-link-color-rgb: 165, 180, 252;
--bs-link-hover-color: #c7d2fe;
--bs-link-hover-color-rgb: 199, 210, 254;
--bs-focus-ring-color: rgba(129, 140, 248, 0.35);
--wdw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -16px rgba(0, 0, 0, 0.7);
--wdw-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px -4px rgba(0, 0, 0, 0.5);
--wdw-stage: #0f1117;
}
body { font-family: var(--wdw-font); -webkit-font-smoothing: antialiased; }
/* Bootstrap compiles its blue into these components; point them at the accent. */
.btn-primary {
--bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
--bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
--bs-btn-disabled-bg: var(--bs-primary); --bs-btn-disabled-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0f1117; --bs-btn-hover-bg: #a5b4fc; --bs-btn-hover-border-color: #a5b4fc; --bs-btn-hover-color: #0f1117; --bs-btn-active-color: #0f1117; }
.btn-outline-primary {
--bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary);
--bs-btn-active-bg: var(--bs-primary); --bs-btn-active-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn { --bs-btn-font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.btn-sm { min-height: 36px; }
.form-control, .form-select { min-height: 44px; border-radius: .75rem; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--bs-primary-rgb), .6); box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--bs-primary); }
.nav { --bs-nav-link-color: var(--bs-secondary-color); --bs-nav-link-hover-color: var(--bs-emphasis-color); }
.pagination { --bs-pagination-active-bg: var(--bs-primary); --bs-pagination-active-border-color: var(--bs-primary); --bs-pagination-color: var(--bs-body-color); --bs-pagination-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--bs-primary); }
.list-group { --bs-list-group-active-bg: var(--bs-primary); --bs-list-group-active-border-color: var(--bs-primary); }
.dropdown-menu { --bs-dropdown-link-active-bg: var(--bs-primary); border-radius: .875rem; box-shadow: var(--wdw-shadow-sm); }
.accordion { --bs-accordion-active-bg: var(--bs-primary-bg-subtle); --bs-accordion-active-color: var(--bs-primary-text-emphasis); --bs-accordion-btn-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.badge { font-weight: 600; }
/* Library building blocks — use these instead of re-inventing them per snippet. */
.wdw-stage { min-height: 100vh; display: flex; align-items: center; background: var(--wdw-stage); padding-block: 3rem; }
.wdw-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: var(--wdw-radius-card); box-shadow: var(--wdw-shadow); }
.wdw-card-sm { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 1rem; box-shadow: var(--wdw-shadow-sm); }
.wdw-aurora { position: relative; color: #fff; background: radial-gradient(60% 55% at 100% 0, #818cf8 0, transparent 70%), radial-gradient(65% 60% at 0 100%, #ec4899 0, transparent 65%), #1e1b4b; }
.wdw-eyebrow { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--bs-primary); }
.wdw-heading { font-weight: 800; letter-spacing: -.02em; color: var(--bs-emphasis-color); }
.wdw-muted { color: var(--bs-secondary-color); }
.wdw-icon { width: 2.75rem; height: 2.75rem; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: .875rem; background: var(--bs-primary-bg-subtle); color: var(--bs-primary); }
/* Component */
.wdw-alerts .alert { border-radius: .875rem; padding: .9rem 3rem .9rem 1rem; font-size: .9375rem; }
.wdw-alerts .alert .btn-close { padding: 1.1rem 1rem; }
.wdw-alerts .alert strong { font-weight: 700; }
.wdw-alerts .alert svg { display: block; }
.wdw-alerts .soft { --c: var(--bs-info); background: color-mix(in srgb, var(--bs-body-bg) 40%, var(--bs-info-bg-subtle)); border: 1px solid var(--bs-info-border-subtle); color: var(--bs-body-color); }
.wdw-alerts .soft .ico { width: 2rem; height: 2rem; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--bs-info-bg-subtle); color: var(--bs-info-text-emphasis); margin-top: -.1rem; }
.wdw-alerts .soft.alert-info { background: color-mix(in srgb, var(--bs-body-bg) 40%, var(--bs-primary-bg-subtle)); border-color: var(--bs-primary-border-subtle); }
.wdw-alerts .soft.alert-info .ico { background: var(--bs-primary-bg-subtle); color: var(--bs-primary-text-emphasis); }
.wdw-alerts .soft.alert-success { background: color-mix(in srgb, var(--bs-body-bg) 40%, var(--bs-success-bg-subtle)); border-color: var(--bs-success-border-subtle); }
.wdw-alerts .soft.alert-success .ico { background: var(--bs-success-bg-subtle); color: var(--bs-success-text-emphasis); }
.wdw-alerts .soft.alert-warning { background: color-mix(in srgb, var(--bs-body-bg) 40%, var(--bs-warning-bg-subtle)); border-color: var(--bs-warning-border-subtle); }
.wdw-alerts .soft.alert-warning .ico { background: var(--bs-warning-bg-subtle); color: var(--bs-warning-text-emphasis); }
.wdw-alerts .soft.alert-danger { background: color-mix(in srgb, var(--bs-body-bg) 40%, var(--bs-danger-bg-subtle)); border-color: var(--bs-danger-border-subtle); }
.wdw-alerts .soft.alert-danger .ico { background: var(--bs-danger-bg-subtle); color: var(--bs-danger-text-emphasis); }
.wdw-alerts .solid { color: #fff; border: 0; }
.wdw-alerts .solid.alert-info { background: #4f46e5; }
.wdw-alerts .solid.alert-success { background: #15803d; }
.wdw-alerts .solid.alert-warning { background: #b45309; }
.wdw-alerts .solid.alert-danger { background: #b91c1c; }
.wdw-alerts .solid .alert-link { text-decoration: underline; }
#toast-stack .toast { border-radius: .875rem; box-shadow: var(--wdw-shadow-sm); }
#toast-stack .ico { width: 1.75rem; height: 1.75rem; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
(function () {
var PATHS = {
info: '<circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/>',
success: '<circle cx="12" cy="12" r="9"/><path d="m8.5 12.5 2.5 2.5 4.5-5"/>',
warning: '<path d="M12 3 2.5 20h19L12 3Z"/><path d="M12 10v4M12 17h.01"/>',
danger: '<circle cx="12" cy="12" r="9"/><path d="m9 9 6 6M15 9l-6 6"/>'
};
var TOASTS = {
info: ['Syncing', 'Syncing your workspace in the background.', 'primary'],
success: ['Settings saved', 'Your preferences were saved successfully.', 'success'],
warning: ['Session expiring', 'Your session expires in 5 minutes.', 'warning'],
danger: ['Something went wrong', 'The request failed. Please try again.', 'danger']
};
function fire(stack, type, delay) {
var t = TOASTS[type];
var el = document.createElement('div');
el.className = 'toast align-items-start border-' + t[2] + '-subtle';
el.setAttribute('role', 'alert');
el.setAttribute('aria-live', 'assertive');
el.setAttribute('aria-atomic', 'true');
el.innerHTML = '<div class="d-flex gap-3 p-3"><span class="ico flex-shrink-0 bg-' + t[2] + '-subtle text-' + t[2] + '-emphasis"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' + PATHS[type] + '</svg></span><div class="me-auto"><strong class="d-block"></strong><span class="small"></span></div><button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button></div>';
el.querySelector('strong').textContent = t[0];
el.querySelector('.small').textContent = t[1];
stack.appendChild(el);
el.addEventListener('hidden.bs.toast', function () { el.remove(); });
new bootstrap.Toast(el, { delay: delay || 5000 }).show();
}
function initAlertTriggers() {
var box = document.getElementById('alert-triggers');
var stack = document.getElementById('toast-stack');
if (!box || !stack) return;
box.addEventListener('click', function (e) {
var btn = e.target.closest('[data-fire]');
if (btn) fire(stack, btn.getAttribute('data-fire'));
});
fire(stack, 'success', 9000);
}
initAlertTriggers();
})();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.