Code library

Free snippets & functions

Copy, adapt and use them in your own projects.

Bootstrap · Respect reduced motion in BootstrapAdvanced
<style>
  .my-fade-in { animation: fadeIn .4s ease both; }
  @keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } }
  @media (prefers-reduced-motion: reduce) {
    .my-fade-in { animation: none; }
  }
</style>
<div class="card my-fade-in"><div class="card-body">I appear smoothly, unless the visitor prefers less motion.</div></div>

Bootstrap already honors it. Add your own animations the same way.

Bootstrap · Load only the Bootstrap parts you useAdvanced
<script type="module">
  import Modal from 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/js/dist/modal.js';
  import Dropdown from 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/js/dist/dropdown.js';
  // Popper is required for dropdowns, tooltips and popovers when you do not use the bundle.
  new Modal(document.getElementById('m'));
</script>
<!-- Or with a bundler:
     import { Modal, Dropdown } from 'bootstrap';  -->

Smaller JavaScript with ES modules.

Bootstrap · Load modal content on demandAdvanced
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#lazy" data-url="/partials/terms.html">Terms</button>

<div class="modal fade" id="lazy" tabindex="-1" aria-labelledby="lazyT" aria-hidden="true">
  <div class="modal-dialog modal-lg modal-dialog-scrollable"><div class="modal-content">
    <div class="modal-header"><h5 class="modal-title" id="lazyT">Terms</h5><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div>
    <div class="modal-body" id="lazyBody"></div>
  </div></div>
</div>

<script>
  document.getElementById('lazy').addEventListener('show.bs.modal', async function (e) {
    var body = document.getElementById('lazyBody');
    body.innerHTML = '<div class="text-center py-5"><div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div></div>';
    try {
      var res = await fetch(e.relatedTarget.dataset.url);
      body.innerHTML = res.ok ? await res.text() : '<p class="text-danger">Could not load.</p>';
    } catch (err) { body.innerHTML = '<p class="text-danger">Network error.</p>'; }
  });
</script>

Fetch the body when the modal opens.

Bootstrap · Light, dark and auto theme switcherAdvanced
<div class="dropdown">
  <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false" aria-label="Theme">Theme</button>
  <ul class="dropdown-menu dropdown-menu-end">
    <li><button type="button" class="dropdown-item" data-mode="light">Light</button></li>
    <li><button type="button" class="dropdown-item" data-mode="dark">Dark</button></li>
    <li><button type="button" class="dropdown-item" data-mode="auto">Auto</button></li>
  </ul>
</div>

<script>
  (function () {
    var mq = window.matchMedia ? matchMedia('(prefers-color-scheme: dark)') : { matches: false, addEventListener: function () {} };
    function apply(mode) {
      var real = mode === 'auto' ? (mq.matches ? 'dark' : 'light') : mode;
      document.documentElement.setAttribute('data-bs-theme', real);
    }
    var mode = 'auto';
    try { mode = localStorage.getItem('mode') || 'auto'; } catch (e) {}
    apply(mode);
    mq.addEventListener('change', function () { if (mode === 'auto') apply('auto'); });
    document.querySelectorAll('[data-mode]').forEach(function (b) {
      b.addEventListener('click', function () {
        mode = b.dataset.mode;
        try { localStorage.setItem('mode', mode); } catch (e) {}
        apply(mode);
      });
    });
  })();
</script>

Three-way switcher that follows the system in auto mode.

Bootstrap · Autocomplete with a dropdownAdvanced
<div class="position-relative">
  <label for="ac" class="form-label">City</label>
  <input type="text" id="ac" class="form-control" autocomplete="off" role="combobox" aria-expanded="false" aria-controls="acList">
  <div id="acList" class="list-group position-absolute w-100 shadow d-none" style="z-index:1050" role="listbox"></div>
</div>

<script>
  var cities = ['Islamabad', 'Lahore', 'Karachi', 'Peshawar', 'Quetta'];
  var input = document.getElementById('ac'), list = document.getElementById('acList');
  input.addEventListener('input', function () {
    var q = input.value.toLowerCase();
    var hits = q ? cities.filter(function (c) { return c.toLowerCase().indexOf(q) === 0; }) : [];
    list.innerHTML = '';
    hits.forEach(function (c) {
      var b = document.createElement('button');
      b.type = 'button'; b.className = 'list-group-item list-group-item-action'; b.setAttribute('role', 'option'); b.textContent = c;
      b.addEventListener('click', function () { input.value = c; list.classList.add('d-none'); input.setAttribute('aria-expanded', 'false'); });
      list.appendChild(b);
    });
    list.classList.toggle('d-none', !hits.length);
    input.setAttribute('aria-expanded', String(hits.length > 0));
  });
</script>

Suggestions below the input.

Bootstrap · Button with loading stateAdvanced
<button type="button" class="btn btn-primary" id="saveBtn">
  <span class="spinner-border spinner-border-sm d-none" aria-hidden="true"></span>
  <span class="label">Save</span>
</button>

<script>
  document.getElementById('saveBtn').addEventListener('click', async function () {
    var btn = this, sp = btn.querySelector('.spinner-border'), label = btn.querySelector('.label');
    btn.disabled = true; sp.classList.remove('d-none'); label.textContent = 'Saving...';
    try { await fetch('/api/save', { method: 'POST' }); label.textContent = 'Saved'; }
    catch (e) { label.textContent = 'Failed'; }
    finally { sp.classList.add('d-none'); setTimeout(function () { btn.disabled = false; label.textContent = 'Save'; }, 1200); }
  });
</script>

Disable and show a spinner while saving.

Bootstrap · Cards that stack by containerAdvanced
<div class="row g-3">
  <div class="col-6 col-lg-3">1</div>
  <div class="col-6 col-lg-3">2</div>
  <div class="w-100 d-none d-md-block d-lg-none"></div>
  <div class="col-6 col-lg-3">3</div>
  <div class="col-6 col-lg-3">4</div>
</div>

Mix breakpoints and break-lines for fine control.

<!-- Icon-only buttons need a name -->
<button type="button" class="btn btn-light" aria-label="Close panel">&times;</button>

<!-- Do not rely on color alone -->
<div class="alert alert-danger" role="alert"><strong>Error:</strong> Please fix the highlighted fields.</div>

<!-- Hidden helper text for screen readers -->
<button type="button" class="btn btn-primary">
  Delete <span class="visually-hidden">invoice 1001</span>
</button>

<!-- Skip link -->
<a class="visually-hidden-focusable" href="#main">Skip to main content</a>

Small details that matter.

Bootstrap · Right-to-left layoutsAdvanced
<!DOCTYPE html>
<html lang="ur" dir="rtl">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>RTL page</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.rtl.min.css" rel="stylesheet">
</head>
<body>
  <div class="container py-4">
    <div class="d-flex gap-3">
      <span class="ms-auto">Pushed to the left in RTL</span>
      <span class="me-2">Margin on the start side</span>
    </div>
  </div>
</body>
</html>

Use the RTL build for Urdu and Arabic.

Bootstrap · Printable invoiceAdvanced
<div class="container my-4">
  <div class="d-print-none mb-3"><button type="button" class="btn btn-primary" onclick="window.print()">Print</button></div>
  <div class="d-flex justify-content-between">
    <h1 class="h3">Invoice #1001</h1>
    <div class="text-end"><div>My Company</div><div class="text-body-secondary small">Islamabad</div></div>
  </div>
  <table class="table mt-4">
    <thead><tr><th scope="col">Item</th><th scope="col" class="text-end">Amount</th></tr></thead>
    <tbody><tr><td>Website</td><td class="text-end">$500</td></tr></tbody>
    <tfoot><tr><th scope="row">Total</th><td class="text-end fw-bold">$500</td></tr></tfoot>
  </table>
</div>

Hide controls when printing.

Bootstrap · Product filters in an offcanvasAdvanced
<button class="btn btn-outline-secondary d-lg-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#flt">Filters</button>
<div class="offcanvas-lg offcanvas-start" tabindex="-1" id="flt" aria-labelledby="fltl">
  <div class="offcanvas-header"><h5 class="offcanvas-title" id="fltl">Filters</h5><button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#flt" aria-label="Close"></button></div>
  <div class="offcanvas-body d-block">
    <h6>Category</h6>
    <div class="form-check"><input class="form-check-input" type="checkbox" id="f1"><label class="form-check-label" for="f1">Books</label></div>
    <div class="form-check"><input class="form-check-input" type="checkbox" id="f2"><label class="form-check-label" for="f2">Pens</label></div>
    <label for="price" class="form-label mt-3">Max price</label>
    <input type="range" class="form-range" id="price" min="0" max="100">
  </div>
</div>

Filter panel on mobile, sidebar on desktop.

Bootstrap · Dashboard top bar with user menuAdvanced
<header class="navbar sticky-top bg-body border-bottom px-3">
  <a class="navbar-brand" href="#">Admin</a>
  <div class="d-flex align-items-center gap-3 ms-auto">
    <button type="button" class="btn btn-light position-relative" aria-label="Notifications">
      &#128276;
      <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">3</span>
    </button>
    <div class="dropdown">
      <a href="#" class="d-flex align-items-center text-decoration-none dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
        <img src="u.jpg" alt="" width="32" height="32" class="rounded-circle me-2"><strong>Ali</strong>
      </a>
      <ul class="dropdown-menu dropdown-menu-end shadow">
        <li><a class="dropdown-item" href="#">Profile</a></li>
        <li><hr class="dropdown-divider"></li>
        <li><a class="dropdown-item" href="#">Sign out</a></li>
      </ul>
    </div>
  </div>
</header>

Search, bell and profile menu.

Bootstrap · Blog list with sidebarAdvanced
<div class="container py-4">
  <div class="row g-4">
    <div class="col-lg-8">
      <article class="card mb-4">
        <div class="card-body">
          <h2 class="h4 card-title"><a href="/post-1" class="stretched-link text-decoration-none">First post</a></h2>
          <p class="card-text text-body-secondary">Short excerpt of the post.</p>
          <small class="text-body-secondary"><time datetime="2026-11-03">3 Nov 2026</time> &middot; 4 min read</small>
        </div>
      </article>
    </div>
    <aside class="col-lg-4">
      <div class="card mb-4"><div class="card-header">Categories</div>
        <ul class="list-group list-group-flush">
          <li class="list-group-item"><a href="#">PHP</a></li>
          <li class="list-group-item"><a href="#">SQL</a></li>
        </ul>
      </div>
    </aside>
  </div>
</div>

Posts on the left, widgets on the right.

Bootstrap · Testimonial cardsAdvanced
<div class="row row-cols-1 row-cols-md-2 g-4">
  <div class="col"><figure class="card card-body h-100 mb-0">
    <blockquote class="blockquote mb-3"><p>"They delivered on time and the quality was excellent."</p></blockquote>
    <figcaption class="blockquote-footer mb-0">Ahmed, <cite title="Company">Acme Ltd</cite></figcaption>
  </figure></div>
  <div class="col"><figure class="card card-body h-100 mb-0">
    <blockquote class="blockquote mb-3"><p>"Clear communication and great technical skill."</p></blockquote>
    <figcaption class="blockquote-footer mb-0">Sara, <cite title="Company">Beta Inc</cite></figcaption>
  </figure></div>
</div>

Quotes with names.

Bootstrap · Landing page feature gridAdvanced
<section class="container py-5" id="features">
  <h2 class="text-center fw-bold mb-5">Why choose us</h2>
  <div class="row row-cols-1 row-cols-md-3 g-4">
    <div class="col">
      <div class="d-inline-flex align-items-center justify-content-center text-bg-primary rounded-3 mb-3" style="width:3rem;height:3rem" aria-hidden="true">&#9889;</div>
      <h3 class="h5">Fast</h3>
      <p class="text-body-secondary">Pages load quickly on any device.</p>
    </div>
    <div class="col">
      <div class="d-inline-flex align-items-center justify-content-center text-bg-success rounded-3 mb-3" style="width:3rem;height:3rem" aria-hidden="true">&#10003;</div>
      <h3 class="h5">Reliable</h3>
      <p class="text-body-secondary">Tested and monitored all day.</p>
    </div>
    <div class="col">
      <div class="d-inline-flex align-items-center justify-content-center text-bg-warning rounded-3 mb-3" style="width:3rem;height:3rem" aria-hidden="true">&#9733;</div>
      <h3 class="h5">Simple</h3>
      <p class="text-body-secondary">Easy to learn, easy to change.</p>
    </div>
  </div>
</section>

Icon, title and text, in a clean grid.

Bootstrap · Docs layout with sticky sidebarAdvanced
<div class="container-xxl">
  <div class="row">
    <aside class="col-lg-3 d-none d-lg-block">
      <nav class="sticky-top pt-4" style="top: 1rem" aria-label="Docs">
        <ul class="nav flex-column">
          <li class="nav-item"><a class="nav-link active" href="#intro">Introduction</a></li>
          <li class="nav-item"><a class="nav-link" href="#install">Install</a></li>
        </ul>
      </nav>
    </aside>
    <main class="col-lg-9 py-4">
      <h1 id="intro">Introduction</h1>
      <h2 id="install">Install</h2>
    </main>
  </div>
</div>

Navigation that follows you.

Bootstrap · A sortable, paged tableAdvanced
<table class="table table-hover" id="dt">
  <thead><tr><th scope="col" role="button">Name</th><th scope="col" role="button">Age</th></tr></thead>
  <tbody>
    <tr><td>Sara</td><td>28</td></tr>
    <tr><td>Ali</td><td>30</td></tr>
    <tr><td>Omar</td><td>22</td></tr>
  </tbody>
</table>
<nav aria-label="Table pages"><ul class="pagination" id="dtp"></ul></nav>

<script>
  var table = document.getElementById('dt'), per = 2, page = 1, dir = 1;
  function rows() { return Array.prototype.slice.call(table.tBodies[0].rows); }
  function render() {
    var all = rows(), pages = Math.ceil(all.length / per);
    all.forEach(function (r, i) { r.classList.toggle('d-none', i < (page - 1) * per || i >= page * per); });
    var ul = document.getElementById('dtp'); ul.innerHTML = '';
    for (var p = 1; p <= pages; p++) {
      var li = document.createElement('li'); li.className = 'page-item' + (p === page ? ' active' : '');
      var a = document.createElement('a'); a.className = 'page-link'; a.href = '#'; a.textContent = p; a.dataset.p = p;
      li.appendChild(a); ul.appendChild(li);
    }
  }
  document.getElementById('dtp').addEventListener('click', function (e) { e.preventDefault(); if (e.target.dataset.p) { page = +e.target.dataset.p; render(); } });
  table.tHead.addEventListener('click', function (e) {
    var th = e.target.closest('th'); if (!th) return;
    var col = th.cellIndex; dir = -dir;
    rows().sort(function (a, b) {
      var x = a.cells[col].textContent, y = b.cells[col].textContent;
      return (isNaN(x) ? x.localeCompare(y) : x - y) * dir;
    }).forEach(function (r) { table.tBodies[0].appendChild(r); });
    render();
  });
  render();
</script>

Click a header to sort, and page through rows.

Bootstrap · Password strength meterAdvanced
<label for="pwd" class="form-label">Password</label>
<input type="password" id="pwd" class="form-control" autocomplete="new-password">
<div class="progress mt-2" style="height:6px" role="progressbar" aria-label="Password strength" aria-valuemin="0" aria-valuemax="4" aria-valuenow="0">
  <div class="progress-bar" id="pbar" style="width:0"></div>
</div>
<div class="form-text" id="ptext">Use 12+ characters.</div>

<script>
  document.getElementById('pwd').addEventListener('input', function () {
    var v = this.value, score = 0;
    if (v.length >= 8) score++;
    if (v.length >= 12) score++;
    if (/[a-z]/.test(v) && /[A-Z]/.test(v)) score++;
    if (/\d/.test(v) && /[^A-Za-z0-9]/.test(v)) score++;
    var bar = document.getElementById('pbar');
    bar.style.width = (score * 25) + '%';
    bar.className = 'progress-bar ' + ['bg-danger', 'bg-danger', 'bg-warning', 'bg-info', 'bg-success'][score];
    document.getElementById('ptext').textContent = ['Too weak', 'Weak', 'Fair', 'Good', 'Strong'][score];
    bar.parentNode.setAttribute('aria-valuenow', score);
  });
</script>

A progress bar that reacts while typing.

Bootstrap · Multi-step form wizardAdvanced
<div class="progress mb-3" role="progressbar" aria-label="Wizard progress" aria-valuemin="0" aria-valuemax="100" aria-valuenow="33">
  <div class="progress-bar" id="wbar" style="width:33%"></div>
</div>
<form id="wizard" novalidate>
  <div class="wstep"><label class="form-label" for="w1">Name</label><input type="text" id="w1" class="form-control" required><div class="invalid-feedback">Required.</div></div>
  <div class="wstep d-none"><label class="form-label" for="w2">Email</label><input type="email" id="w2" class="form-control" required><div class="invalid-feedback">Valid email required.</div></div>
  <div class="wstep d-none"><p>All done. Submit?</p></div>
  <div class="d-flex justify-content-between mt-3">
    <button type="button" class="btn btn-light" id="wprev">Back</button>
    <button type="button" class="btn btn-primary" id="wnext">Next</button>
  </div>
</form>

<script>
  var steps = document.querySelectorAll('.wstep'), idx = 0;
  function show(i) {
    idx = i;
    steps.forEach(function (s, n) { s.classList.toggle('d-none', n !== i); });
    document.getElementById('wbar').style.width = Math.round(((i + 1) / steps.length) * 100) + '%';
    document.getElementById('wprev').disabled = i === 0;
    document.getElementById('wnext').textContent = i === steps.length - 1 ? 'Submit' : 'Next';
  }
  document.getElementById('wnext').addEventListener('click', function () {
    var inputs = steps[idx].querySelectorAll('input');
    var ok = true;
    inputs.forEach(function (inp) { var v = inp.checkValidity(); inp.classList.toggle('is-invalid', !v); if (!v) ok = false; });
    if (!ok) return;
    if (idx === steps.length - 1) return document.getElementById('wizard').submit();
    show(idx + 1);
  });
  document.getElementById('wprev').addEventListener('click', function () { show(idx - 1); });
  show(0);
</script>

Validate each step before continuing.

Bootstrap · A toast helper with a queueAdvanced
<div class="toast-container position-fixed top-0 end-0 p-3" id="tc" aria-live="polite" aria-atomic="true"></div>

<script>
  var MAX = 3, waiting = [];
  function notify(text, type) {
    var box = document.getElementById('tc');
    if (box.children.length >= MAX) { waiting.push([text, type]); return; }
    var el = document.createElement('div');
    el.className = 'toast text-bg-' + (type || 'dark') + ' border-0';
    el.setAttribute('role', 'status');
    var body = document.createElement('div');
    body.className = 'toast-body';
    body.textContent = text;
    el.appendChild(body);
    box.appendChild(el);
    el.addEventListener('hidden.bs.toast', function () {
      el.remove();
      if (waiting.length) { var n = waiting.shift(); notify(n[0], n[1]); }
    });
    bootstrap.Toast.getOrCreateInstance(el, { delay: 3500 }).show();
  }
</script>

Never more than three toasts at once.

Bootstrap · Offcanvas with events and scrollingAdvanced
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#filters" data-bs-scroll="true" data-bs-backdrop="false">Filters</button>

<div class="offcanvas offcanvas-end" tabindex="-1" id="filters" aria-labelledby="fl" data-bs-scroll="true" data-bs-backdrop="false">
  <div class="offcanvas-header"><h5 class="offcanvas-title" id="fl">Filters</h5><button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button></div>
  <div class="offcanvas-body">Filter controls</div>
</div>

<script>
  document.getElementById('filters').addEventListener('hidden.bs.offcanvas', function () { console.log('filters closed'); });
</script>

Keep the page scrollable and the backdrop off.

Bootstrap · Collapse with JavaScriptAdvanced
<button type="button" class="btn btn-primary" id="tgl">Toggle</button>
<div class="collapse" id="panel"><div class="card card-body mt-2">Content</div></div>

<script>
  var panel = document.getElementById('panel');
  var c = new bootstrap.Collapse(panel, { toggle: false });
  document.getElementById('tgl').addEventListener('click', function () { c.toggle(); });
  panel.addEventListener('shown.bs.collapse', function () { console.log('opened'); });
  panel.addEventListener('hidden.bs.collapse', function () { console.log('closed'); });
</script>

Open, close and react from code.

Bootstrap · Control the carousel with JavaScriptAdvanced
<div id="c" class="carousel slide" data-bs-ride="false">
  <div class="carousel-inner">
    <div class="carousel-item active"><div class="p-5 bg-body-secondary">One</div></div>
    <div class="carousel-item"><div class="p-5 bg-body-secondary">Two</div></div>
  </div>
</div>
<button type="button" class="btn btn-sm btn-primary" id="goto2">Go to 2</button>

<script>
  var el = document.getElementById('c');
  var carousel = bootstrap.Carousel.getOrCreateInstance(el, { interval: 4000, pause: 'hover', touch: true });
  el.addEventListener('slid.bs.carousel', function (e) { console.log('Now showing', e.to); });
  document.getElementById('goto2').addEventListener('click', function () { carousel.to(1); });
</script>

Pause on hover, listen to changes, jump to a slide.

Bootstrap · Popover with sanitized HTMLAdvanced
<button type="button" class="btn btn-outline-secondary" id="pop">Details</button>

<script>
  var allow = bootstrap.Tooltip.Default.allowList;
  allow.table = [];
  new bootstrap.Popover(document.getElementById('pop'), {
    html: true,
    trigger: 'focus',
    title: 'Order',
    content: '<table class="table table-sm mb-0"><tr><td>Item</td><td>Pen</td></tr></table>',
    sanitize: true
  });
</script>

Allow some HTML safely.

Bootstrap · Tooltips for content added laterAdvanced
<div id="list" class="list-group"></div>

<script>
  new bootstrap.Tooltip(document.body, { selector: '[data-bs-toggle="tooltip"]', trigger: 'hover focus' });

  var item = document.createElement('button');
  item.type = 'button';
  item.className = 'list-group-item list-group-item-action';
  item.setAttribute('data-bs-toggle', 'tooltip');
  item.setAttribute('data-bs-title', 'Added later');
  item.textContent = 'Dynamic row';
  document.getElementById('list').appendChild(item);
</script>

Use the selector option to cover future elements.

Bootstrap · Tabs that remember the URL hashAdvanced
<ul class="nav nav-tabs" role="tablist">
  <li class="nav-item" role="presentation"><button class="nav-link active" data-bs-toggle="tab" data-bs-target="#overview" type="button" role="tab" aria-selected="true">Overview</button></li>
  <li class="nav-item" role="presentation"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#billing" type="button" role="tab" aria-selected="false">Billing</button></li>
</ul>
<div class="tab-content pt-3">
  <div class="tab-pane fade show active" id="overview" role="tabpanel">Overview</div>
  <div class="tab-pane fade" id="billing" role="tabpanel">Billing</div>
</div>

<script>
  document.querySelectorAll('[data-bs-toggle="tab"]').forEach(function (btn) {
    btn.addEventListener('shown.bs.tab', function (e) {
      history.replaceState(null, '', e.target.getAttribute('data-bs-target'));
    });
  });
  if (location.hash) {
    var t = document.querySelector('[data-bs-target="' + location.hash + '"]');
    if (t) bootstrap.Tab.getOrCreateInstance(t).show();
  }
</script>

Open a tab from a link and keep it after refresh.

Bootstrap · A reusable confirm dialogAdvanced
<div class="modal fade" id="confirmModal" tabindex="-1" aria-labelledby="confirmTitle" aria-hidden="true">
  <div class="modal-dialog modal-sm modal-dialog-centered"><div class="modal-content">
    <div class="modal-body"><h2 class="h6" id="confirmTitle">Are you sure?</h2><p id="confirmText" class="mb-0"></p></div>
    <div class="modal-footer">
      <button type="button" class="btn btn-light" data-answer="no">Cancel</button>
      <button type="button" class="btn btn-danger" data-answer="yes">Confirm</button>
    </div>
  </div></div>
</div>

<script>
  function confirmBox(text) {
    return new Promise(function (resolve) {
      var el = document.getElementById('confirmModal');
      var modal = bootstrap.Modal.getOrCreateInstance(el);
      var answer = false;
      el.querySelector('#confirmText').textContent = text;
      function onClick(e) {
        var b = e.target.closest('[data-answer]');
        if (!b) return;
        answer = b.dataset.answer === 'yes';
        modal.hide();
      }
      el.addEventListener('click', onClick);
      el.addEventListener('hidden.bs.modal', function done() {
        el.removeEventListener('click', onClick);
        el.removeEventListener('hidden.bs.modal', done);
        resolve(answer);
      });
      modal.show();
    });
  }
  // if (await confirmBox('Delete this item?')) { ... }
</script>

One modal for every "Are you sure?" with a promise.

$grid-breakpoints: (
  xs: 0,
  sm: 480px,
  md: 768px,
  lg: 1024px,
  xl: 1280px,
  xxl: 1600px
);

$container-max-widths: (
  sm: 456px,
  md: 720px,
  lg: 980px,
  xl: 1240px,
  xxl: 1520px
);

Make the grid fit your design.

Bootstrap · Add your own utilities (Sass API)Advanced
// after importing bootstrap/scss/utilities
$utilities: map-merge(
  $utilities,
  (
    "cursor": (
      property: cursor,
      class: cursor,
      values: auto pointer grab not-allowed
    ),
    "opacity": map-merge(map-get($utilities, "opacity"), (
      values: map-merge(map-get(map-get($utilities, "opacity"), "values"), (10: .1))
    ))
  )
);
// Result: .cursor-pointer, .cursor-grab, .opacity-10

Generate new helper classes from a map.

Bootstrap · Customize Bootstrap with SassAdvanced
// custom.scss
$primary: #7c3aed;
$font-family-sans-serif: "Inter", system-ui, sans-serif;
$border-radius: 0.75rem;
$enable-shadows: true;
$enable-rounded: true;
$grid-gutter-width: 1.5rem;

@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/variables-dark";
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/utilities";

@import "bootstrap/scss/root";
@import "bootstrap/scss/reboot";
@import "bootstrap/scss/containers";
@import "bootstrap/scss/grid";
@import "bootstrap/scss/buttons";
@import "bootstrap/scss/forms";
@import "bootstrap/scss/utilities/api";

Override variables before importing Bootstrap and include only what you need.