Bootstrap 5 Product List with Add to Cart Animation
A responsive product grid where each Add button turns into a quantity stepper and updates a live cart badge and total.
<section class="wdw-stage">
<div class="container" style="max-width:1100px">
<div class="d-flex flex-wrap align-items-end justify-content-between gap-3 mb-4">
<div>
<span class="wdw-eyebrow">New arrivals</span>
<h2 class="wdw-heading h2 mb-0">Shop the latest drops</h2>
</div>
<button type="button" class="btn btn-outline-primary rounded-pill position-relative me-2 pl-cart" aria-label="Cart, 0 items">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="9" cy="20" r="1.5"/><circle cx="18" cy="20" r="1.5"/><path d="M2 3h3l2.7 12.4a2 2 0 0 0 2 1.6h7.7a2 2 0 0 0 2-1.5L21 8H6"/></svg>
<span class="pl-total">$0</span>
<span class="pl-count badge rounded-pill bg-primary position-absolute top-0 start-100 translate-middle">0</span>
</button>
</div>
<div class="row g-4">
<div class="col-sm-6 col-lg-3">
<article class="wdw-card pl-card h-100 p-3 d-flex flex-column" data-product="Crimson Runner" data-price="89">
<div class="pl-media ratio ratio-1x1 rounded-4 overflow-hidden mb-3">
<img src="https://images.unsplash.com/photo-1542291026-7eec264c27ff?auto=format&fit=crop&w=600&q=70" alt="Crimson Runner" loading="lazy">
</div>
<span class="wdw-eyebrow mb-1">Sneakers</span>
<h3 class="h6 fw-bold mb-1 text-body-emphasis">Crimson Runner</h3>
<p class="small wdw-muted mb-3">Lightweight trainer</p>
<div class="d-flex align-items-center justify-content-between mt-auto gap-2">
<span class="fs-5 fw-bold text-body-emphasis">$89</span>
<div class="pl-action">
<button type="button" class="btn btn-primary btn-sm rounded-pill px-3 pl-add"><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"><path d="M12 5v14M5 12h14"/></svg>Add</button>
<div class="pl-stepper d-none align-items-center rounded-pill" role="group" aria-label="Quantity for Crimson Runner">
<button type="button" class="pl-step" data-step="-1" aria-label="Remove one Crimson Runner">−</button>
<span class="pl-qty fw-bold" aria-live="polite">1</span>
<button type="button" class="pl-step" data-step="1" aria-label="Add one Crimson Runner">+</button>
</div>
</div>
</div>
</article>
</div>
<div class="col-sm-6 col-lg-3">
<article class="wdw-card pl-card h-100 p-3 d-flex flex-column" data-product="Meridian Watch" data-price="129">
<div class="pl-media ratio ratio-1x1 rounded-4 overflow-hidden mb-3">
<img src="https://images.unsplash.com/photo-1523275335684-37898b6baf30?auto=format&fit=crop&w=600&q=70" alt="Meridian Watch" loading="lazy">
</div>
<span class="wdw-eyebrow mb-1">Watches</span>
<h3 class="h6 fw-bold mb-1 text-body-emphasis">Meridian Watch</h3>
<p class="small wdw-muted mb-3">Steel case, 40mm</p>
<div class="d-flex align-items-center justify-content-between mt-auto gap-2">
<span class="fs-5 fw-bold text-body-emphasis">$129</span>
<div class="pl-action">
<button type="button" class="btn btn-primary btn-sm rounded-pill px-3 pl-add"><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"><path d="M12 5v14M5 12h14"/></svg>Add</button>
<div class="pl-stepper d-none align-items-center rounded-pill" role="group" aria-label="Quantity for Meridian Watch">
<button type="button" class="pl-step" data-step="-1" aria-label="Remove one Meridian Watch">−</button>
<span class="pl-qty fw-bold" aria-live="polite">1</span>
<button type="button" class="pl-step" data-step="1" aria-label="Add one Meridian Watch">+</button>
</div>
</div>
</div>
</article>
</div>
<div class="col-sm-6 col-lg-3">
<article class="wdw-card pl-card h-100 p-3 d-flex flex-column" data-product="Halo Headphones" data-price="149">
<div class="pl-media ratio ratio-1x1 rounded-4 overflow-hidden mb-3">
<img src="https://images.unsplash.com/photo-1505740420928-5e560c06d30e?auto=format&fit=crop&w=600&q=70" alt="Halo Headphones" loading="lazy">
</div>
<span class="wdw-eyebrow mb-1">Audio</span>
<h3 class="h6 fw-bold mb-1 text-body-emphasis">Halo Headphones</h3>
<p class="small wdw-muted mb-3">Wireless, 30h battery</p>
<div class="d-flex align-items-center justify-content-between mt-auto gap-2">
<span class="fs-5 fw-bold text-body-emphasis">$149</span>
<div class="pl-action">
<button type="button" class="btn btn-primary btn-sm rounded-pill px-3 pl-add"><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"><path d="M12 5v14M5 12h14"/></svg>Add</button>
<div class="pl-stepper d-none align-items-center rounded-pill" role="group" aria-label="Quantity for Halo Headphones">
<button type="button" class="pl-step" data-step="-1" aria-label="Remove one Halo Headphones">−</button>
<span class="pl-qty fw-bold" aria-live="polite">1</span>
<button type="button" class="pl-step" data-step="1" aria-label="Add one Halo Headphones">+</button>
</div>
</div>
</div>
</article>
</div>
<div class="col-sm-6 col-lg-3">
<article class="wdw-card pl-card h-100 p-3 d-flex flex-column" data-product="Atlas Tee" data-price="34">
<div class="pl-media ratio ratio-1x1 rounded-4 overflow-hidden mb-3">
<img src="https://images.unsplash.com/photo-1583743814966-8936f5b7be1a?auto=format&fit=crop&w=600&q=70" alt="Atlas Tee" loading="lazy">
</div>
<span class="wdw-eyebrow mb-1">Apparel</span>
<h3 class="h6 fw-bold mb-1 text-body-emphasis">Atlas Tee</h3>
<p class="small wdw-muted mb-3">Organic cotton</p>
<div class="d-flex align-items-center justify-content-between mt-auto gap-2">
<span class="fs-5 fw-bold text-body-emphasis">$34</span>
<div class="pl-action">
<button type="button" class="btn btn-primary btn-sm rounded-pill px-3 pl-add"><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"><path d="M12 5v14M5 12h14"/></svg>Add</button>
<div class="pl-stepper d-none align-items-center rounded-pill" role="group" aria-label="Quantity for Atlas Tee">
<button type="button" class="pl-step" data-step="-1" aria-label="Remove one Atlas Tee">−</button>
<span class="pl-qty fw-bold" aria-live="polite">1</span>
<button type="button" class="pl-step" data-step="1" aria-label="Add one Atlas Tee">+</button>
</div>
</div>
</div>
</article>
</div>
</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 */
.pl-card { transition: transform .25s ease, box-shadow .25s ease; }
.pl-card:hover { transform: translateY(-4px); }
.pl-media { background: var(--bs-tertiary-bg); }
.pl-media img { object-fit: cover; transition: transform .5s ease; }
.pl-card:hover .pl-media img { transform: scale(1.06); }
.pl-stepper { background: var(--bs-primary-bg-subtle); height: 36px; padding: 0 .25rem; animation: pl-pop .3s ease-out; }
.pl-stepper.d-flex { display: inline-flex !important; }
.pl-step { width: 32px; height: 32px; border: 0; border-radius: 50%; background: transparent; color: var(--bs-primary); font-size: 1.1rem; font-weight: 700; line-height: 1; }
.pl-step:hover { background: rgba(var(--bs-primary-rgb), .15); }
.pl-step:focus-visible { outline: 2px solid var(--bs-primary); }
.pl-qty { min-width: 1.75rem; text-align: center; font-size: .875rem; color: var(--bs-primary-text-emphasis); }
.pl-count.bump { animation: pl-bump .35s ease; }
@keyframes pl-pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pl-bump { 50% { transform: translate(-50%, -50%) scale(1.35); } }
@media (prefers-reduced-motion: reduce) { .pl-card, .pl-media img, .pl-stepper { animation: none; transition: none; } }
function initProductList() {
var cards = document.querySelectorAll('.pl-card');
var cart = document.querySelector('.pl-cart');
if (!cards.length || !cart) return;
var totalEl = cart.querySelector('.pl-total');
var countEl = cart.querySelector('.pl-count');
function update() {
var count = 0, total = 0;
cards.forEach(function (card) {
var q = parseInt(card.dataset.qty || '0', 10);
count += q;
total += q * parseFloat(card.dataset.price);
});
totalEl.textContent = '$' + total;
countEl.textContent = count;
cart.setAttribute('aria-label', 'Cart, ' + count + ' items, $' + total);
countEl.classList.remove('bump');
void countEl.offsetWidth;
countEl.classList.add('bump');
}
function setQty(card, q) {
q = Math.max(0, q);
card.dataset.qty = q;
var add = card.querySelector('.pl-add');
var stepper = card.querySelector('.pl-stepper');
add.classList.toggle('d-none', q > 0);
stepper.classList.toggle('d-none', q === 0);
stepper.classList.toggle('d-flex', q > 0);
card.querySelector('.pl-qty').textContent = q;
update();
(q > 0 ? stepper.querySelector('[data-step="1"]') : add).focus();
}
cards.forEach(function (card) {
card.querySelector('.pl-add').addEventListener('click', function () { setQty(card, 1); });
card.querySelectorAll('.pl-step').forEach(function (b) {
b.addEventListener('click', function () {
setQty(card, parseInt(card.dataset.qty || '0', 10) + parseInt(b.dataset.step, 10));
});
});
});
}
initProductList();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.