Bootstrap 5 Product Grid with Hover Add to Cart
A product grid where each card lifts on hover, zooms the photo and reveals an add-to-cart button, with a save toggle and a live cart counter.
<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 mt-1 mb-0">Shop the collection</h2>
</div>
<div class="pl-cart wdw-card-sm px-3 py-2 d-flex align-items-center gap-2" role="status" aria-live="polite">
<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="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/><path d="M1 1h4l2.7 13.4a2 2 0 0 0 2 1.6h9.7a2 2 0 0 0 2-1.6L23 6H6"/></svg>
<span class="small fw-semibold"><span id="plCount">0</span> items in cart</span>
</div>
</div>
<div class="row g-3 g-lg-4">
<div class="col-6 col-lg-3">
<article class="pl-card wdw-card-sm h-100">
<div class="pl-img">
<img src="https://images.unsplash.com/photo-1542291026-7eec264c27ff?w=600&h=600&fit=crop" alt="Red Racing Sneakers" loading="lazy">
<button type="button" class="pl-fav" aria-pressed="false" aria-label="Save Red Racing Sneakers"><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="M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.7l-1-1.1a5.5 5.5 0 0 0-7.8 7.8l1 1.1L12 21l7.8-7.5 1-1.1a5.5 5.5 0 0 0 0-7.8z"/></svg></button>
<button type="button" class="btn btn-primary btn-sm rounded-pill pl-add" data-name="Red Racing Sneakers">Add to cart</button>
</div>
<div class="p-3">
<div class="small wdw-muted">Footwear</div>
<h3 class="h6 fw-bold mb-1">Red Racing Sneakers</h3>
<div class="fw-bold text-primary">$89</div>
</div>
</article>
</div>
<div class="col-6 col-lg-3">
<article class="pl-card wdw-card-sm h-100">
<div class="pl-img">
<img src="https://images.unsplash.com/photo-1523275335684-37898b6baf30?w=600&h=600&fit=crop" alt="Smart Watch" loading="lazy">
<button type="button" class="pl-fav" aria-pressed="false" aria-label="Save Smart Watch"><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="M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.7l-1-1.1a5.5 5.5 0 0 0-7.8 7.8l1 1.1L12 21l7.8-7.5 1-1.1a5.5 5.5 0 0 0 0-7.8z"/></svg></button>
<button type="button" class="btn btn-primary btn-sm rounded-pill pl-add" data-name="Smart Watch">Add to cart</button>
</div>
<div class="p-3">
<div class="small wdw-muted">Wearables</div>
<h3 class="h6 fw-bold mb-1">Smart Watch</h3>
<div class="fw-bold text-primary">$120</div>
</div>
</article>
</div>
<div class="col-6 col-lg-3">
<article class="pl-card wdw-card-sm h-100">
<div class="pl-img">
<img src="https://images.unsplash.com/photo-1505740420928-5e560c06d30e?w=600&h=600&fit=crop" alt="Studio Headphones" loading="lazy">
<button type="button" class="pl-fav" aria-pressed="false" aria-label="Save Studio Headphones"><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="M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.7l-1-1.1a5.5 5.5 0 0 0-7.8 7.8l1 1.1L12 21l7.8-7.5 1-1.1a5.5 5.5 0 0 0 0-7.8z"/></svg></button>
<button type="button" class="btn btn-primary btn-sm rounded-pill pl-add" data-name="Studio Headphones">Add to cart</button>
</div>
<div class="p-3">
<div class="small wdw-muted">Audio</div>
<h3 class="h6 fw-bold mb-1">Studio Headphones</h3>
<div class="fw-bold text-primary">$149</div>
</div>
</article>
</div>
<div class="col-6 col-lg-3">
<article class="pl-card wdw-card-sm h-100">
<div class="pl-img">
<img src="https://images.unsplash.com/photo-1572635196237-14b3f281503f?w=600&h=600&fit=crop" alt="Aviator Sunglasses" loading="lazy">
<button type="button" class="pl-fav" aria-pressed="false" aria-label="Save Aviator Sunglasses"><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="M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.7l-1-1.1a5.5 5.5 0 0 0-7.8 7.8l1 1.1L12 21l7.8-7.5 1-1.1a5.5 5.5 0 0 0 0-7.8z"/></svg></button>
<button type="button" class="btn btn-primary btn-sm rounded-pill pl-add" data-name="Aviator Sunglasses">Add to cart</button>
</div>
<div class="p-3">
<div class="small wdw-muted">Accessories</div>
<h3 class="h6 fw-bold mb-1">Aviator Sunglasses</h3>
<div class="fw-bold text-primary">$64</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 { overflow: hidden; transition: transform .2s ease, box-shadow .2s ease; }
.pl-card:hover { transform: translateY(-4px); box-shadow: var(--wdw-shadow); }
.pl-img { position: relative; aspect-ratio: 1; overflow: hidden; background: var(--bs-tertiary-bg); }
.pl-img img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s ease; }
.pl-card:hover .pl-img img { transform: scale(1.06); }
.pl-add { position: absolute; left: .75rem; right: .75rem; bottom: .75rem; transform: translateY(150%); opacity: 0; transition: transform .25s ease, opacity .25s ease; }
.pl-card:hover .pl-add, .pl-add:focus-visible { transform: none; opacity: 1; }
@media (hover: none) { .pl-add { transform: none; opacity: 1; } }
.pl-fav { position: absolute; top: .75rem; right: .75rem; width: 44px; height: 44px; border: 0; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: rgba(255,255,255,.92); color: #374151; box-shadow: var(--wdw-shadow-sm); transition: color .15s; }
.pl-fav[aria-pressed="true"] { color: #e11d48; }
.pl-fav[aria-pressed="true"] svg { fill: currentColor; }
.pl-add.is-added { --bs-btn-bg: var(--bs-success); --bs-btn-border-color: var(--bs-success); --bs-btn-hover-bg: var(--bs-success); --bs-btn-hover-border-color: var(--bs-success); }
@media (prefers-reduced-motion: reduce) { .pl-card, .pl-img img, .pl-add { transition: none; } .pl-card:hover { transform: none; } }
function initFavourites() {
document.querySelectorAll('.pl-fav').forEach(function (btn) {
btn.addEventListener('click', function () {
btn.setAttribute('aria-pressed', btn.getAttribute('aria-pressed') === 'true' ? 'false' : 'true');
});
});
}
function initAddToCart() {
var counter = document.getElementById('plCount');
if (!counter) return;
var count = 0;
document.querySelectorAll('.pl-add').forEach(function (btn) {
btn.addEventListener('click', function () {
count += 1;
counter.textContent = count;
btn.classList.add('is-added');
btn.textContent = 'Added';
setTimeout(function () { btn.classList.remove('is-added'); btn.textContent = 'Add to cart'; }, 1400);
});
});
}
initFavourites();
initAddToCart();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.