Bootstrap 5 Product Card with Hover Zoom
An e-commerce product card with a zoom-on-hover photo, discount badge, wishlist toggle, colour swatches and an add-to-cart button that confirms the action.
<section class="wdw-stage">
<div class="container" style="max-width:980px">
<article class="wdw-card product overflow-hidden" data-imgs='{"graphite":["https://images.unsplash.com/photo-1546435770-a3e426bf472b?auto=format&fit=crop&w=1000&q=80","Black headphones on a white desk"],"stone":["https://images.unsplash.com/photo-1618366712010-f4ae9c647dcb?auto=format&fit=crop&w=1000&q=80","Headphones on a warm stone backdrop"],"cloud":["https://images.unsplash.com/photo-1583394838336-acd977736f90?auto=format&fit=crop&w=1000&q=80","Wired headphones on a white background"]}'>
<div class="row g-0">
<div class="col-md-6 product-gallery p-3 p-md-4 bg-body-tertiary">
<div class="product-media position-relative rounded-4 overflow-hidden">
<span class="badge rounded-pill text-bg-danger position-absolute top-0 start-0 m-3 px-3 py-2 fs-6 fw-bold d-inline-flex align-items-center" style="height:44px">-20%</span>
<button type="button" class="btn btn-light rounded-circle position-absolute top-0 end-0 m-3 p-0 shadow-sm" style="width:44px;height:44px" id="wishBtn" aria-pressed="false" aria-label="Add to wishlist">
<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="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 1L12 21l7.8-7.6 1-1a5.5 5.5 0 0 0 0-7.8Z"/></svg>
</button>
<img src="https://images.unsplash.com/photo-1546435770-a3e426bf472b?auto=format&fit=crop&w=1000&q=80" alt="Black headphones on a white desk" class="product-img" id="productImg" width="1000" height="1000">
</div>
<div class="d-flex gap-2 mt-3"><button type="button" class="thumb is-on" data-color="graphite" aria-label="Show Graphite view"><img src="https://images.unsplash.com/photo-1546435770-a3e426bf472b?auto=format&fit=crop&w=200&h=200&q=70" alt="" width="72" height="72"></button><button type="button" class="thumb" data-color="stone" aria-label="Show Stone view"><img src="https://images.unsplash.com/photo-1618366712010-f4ae9c647dcb?auto=format&fit=crop&w=200&h=200&q=70" alt="" width="72" height="72"></button><button type="button" class="thumb" data-color="cloud" aria-label="Show Cloud view"><img src="https://images.unsplash.com/photo-1583394838336-acd977736f90?auto=format&fit=crop&w=200&h=200&q=70" alt="" width="72" height="72"></button></div>
</div>
<div class="col-md-6 p-4 p-md-5 d-flex flex-column justify-content-center">
<span class="wdw-eyebrow">Audio</span>
<h1 class="wdw-heading h2 mt-1 mb-2">COX Wireless Headphones</h1>
<div class="d-flex align-items-center gap-2 small mb-3" role="img" aria-label="Rated 4.6 out of 5 from 218 reviews"><span class="d-inline-flex gap-1 text-warning" aria-hidden="true"><svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="1.75" stroke-linejoin="round" aria-hidden="true"><path d="m12 2.5 2.9 6 6.6.9-4.8 4.6 1.2 6.5L12 17.4l-5.9 3.1 1.2-6.5L2.5 9.4l6.6-.9Z"/></svg><svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="1.75" stroke-linejoin="round" aria-hidden="true"><path d="m12 2.5 2.9 6 6.6.9-4.8 4.6 1.2 6.5L12 17.4l-5.9 3.1 1.2-6.5L2.5 9.4l6.6-.9Z"/></svg><svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="1.75" stroke-linejoin="round" aria-hidden="true"><path d="m12 2.5 2.9 6 6.6.9-4.8 4.6 1.2 6.5L12 17.4l-5.9 3.1 1.2-6.5L2.5 9.4l6.6-.9Z"/></svg><svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="1.75" stroke-linejoin="round" aria-hidden="true"><path d="m12 2.5 2.9 6 6.6.9-4.8 4.6 1.2 6.5L12 17.4l-5.9 3.1 1.2-6.5L2.5 9.4l6.6-.9Z"/></svg><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linejoin="round" aria-hidden="true"><path d="m12 2.5 2.9 6 6.6.9-4.8 4.6 1.2 6.5L12 17.4l-5.9 3.1 1.2-6.5L2.5 9.4l6.6-.9Z"/></svg></span><span class="wdw-muted" aria-hidden="true">4.6 (218 reviews)</span></div>
<p class="wdw-muted mb-4">40-hour battery, active noise cancelling and plush memory-foam cushions for all-day comfort.</p>
<div class="mb-4"><span class="display-6 fw-bolder">$99</span><span class="wdw-muted text-decoration-line-through ms-2">$124</span></div>
<div class="mb-4">
<div class="small fw-semibold mb-2">Colour: <span id="colorName" class="wdw-muted fw-normal">Graphite</span></div>
<div class="d-flex gap-3" role="radiogroup" aria-label="Colour"><button type="button" class="swatch is-on" style="--c:#1f2937" role="radio" aria-checked="true" aria-label="Graphite" data-color="graphite"></button><button type="button" class="swatch" style="--c:#c9b6a8" role="radio" aria-checked="false" aria-label="Stone" data-color="stone"></button><button type="button" class="swatch" style="--c:#e5e7eb" role="radio" aria-checked="false" aria-label="Cloud" data-color="cloud"></button></div>
</div>
<button type="button" class="btn btn-primary rounded-pill w-100" id="addBtn"><svg class="d-none" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12 5 5 9-10"/></svg><span id="addLabel">Add to cart</span></button>
<div class="visually-hidden" role="status" aria-live="polite" id="addStatus"></div>
</div>
</div>
</article>
</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 */
.product-media { background: var(--bs-body-bg); }
.product-img { width: 100%; height: auto; aspect-ratio: 1 / 1; object-fit: cover; display: block; transition: opacity .25s ease, transform .6s cubic-bezier(.2, .7, .2, 1); }
.product:hover .product-img { transform: scale(1.04); }
.product-img.is-swap { opacity: 0; }
.thumb { width: 72px; height: 72px; padding: 0; border: 2px solid transparent; border-radius: .875rem; overflow: hidden; background: var(--bs-body-bg); opacity: .75; position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.is-on { border-color: var(--bs-primary); opacity: 1; }
.thumb:focus-visible, .swatch:focus-visible { outline: 3px solid var(--bs-primary); outline-offset: 2px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--bs-body-bg); background: var(--c); box-shadow: 0 0 0 1px var(--bs-border-color), inset 0 0 0 1px rgba(128,128,128,.35); padding: 0; position: relative; }
.swatch::before { content: ""; position: absolute; inset: -8px; }
.swatch.is-on { box-shadow: 0 0 0 3px var(--bs-primary); }
[data-bs-theme="dark"] .swatch { border-color: var(--bs-secondary-color); }
[data-bs-theme="dark"] .swatch.is-on { border-color: var(--bs-body-bg); box-shadow: 0 0 0 3px var(--bs-primary); }
#wishBtn[aria-pressed="true"] { color: #dc2626; }
#wishBtn[aria-pressed="true"] svg { fill: currentColor; }
#addBtn.is-added { background: var(--bs-success); border-color: var(--bs-success); color: #fff; }
@media (prefers-reduced-motion: reduce) { .product-img { transition: none; } }
(function () {
function initColors() {
var card = document.querySelector('.product');
if (!card) return;
var data = JSON.parse(card.getAttribute('data-imgs'));
var img = document.getElementById('productImg');
var name = document.getElementById('colorName');
var sw = card.querySelectorAll('.swatch');
var th = card.querySelectorAll('.thumb');
function select(key) {
var d = data[key]; if (!d) return;
sw.forEach(function (s) { var on = s.dataset.color === key; s.classList.toggle('is-on', on); s.setAttribute('aria-checked', String(on)); if (on) name.textContent = s.getAttribute('aria-label'); });
th.forEach(function (t) { var on = t.dataset.color === key; t.classList.toggle('is-on', on); t.setAttribute('aria-pressed', String(on)); });
img.classList.add('is-swap');
setTimeout(function () { img.src = d[0]; img.alt = d[1]; img.classList.remove('is-swap'); }, 150);
}
sw.forEach(function (s) { s.addEventListener('click', function () { select(s.dataset.color); }); });
th.forEach(function (t) { t.addEventListener('click', function () { select(t.dataset.color); }); });
}
function initWishlist() {
var b = document.getElementById('wishBtn');
if (!b) return;
b.addEventListener('click', function () {
var on = b.getAttribute('aria-pressed') === 'true';
b.setAttribute('aria-pressed', String(!on));
b.setAttribute('aria-label', on ? 'Add to wishlist' : 'Remove from wishlist');
});
}
function initAddToCart() {
var b = document.getElementById('addBtn');
if (!b) return;
var label = document.getElementById('addLabel');
var status = document.getElementById('addStatus');
var icon = b.querySelector('svg');
var t;
b.addEventListener('click', function () {
label.textContent = 'Added to cart';
icon.classList.remove('d-none'); b.classList.add('is-added');
status.textContent = 'COX Wireless Headphones added to your cart.';
clearTimeout(t);
t = setTimeout(function () {
label.textContent = 'Add to cart'; icon.classList.add('d-none'); b.classList.remove('is-added'); status.textContent = '';
}, 1800);
});
}
initColors(); initWishlist(); initAddToCart();
})();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.