Bootstrap 5 Product Card with Add to Cart Button
A single product card with image, badge, wishlist toggle, price, rating and clear add-to-cart and view-details buttons.
<section class="wdw-stage">
<div class="container" style="max-width:860px">
<article class="wdw-card overflow-hidden pc row g-0 mx-auto">
<div class="pc-media position-relative col-md-6">
<img src="https://images.unsplash.com/photo-1523275335684-37898b6baf30?w=600&q=80" alt="White smartwatch with a black display and silicone strap">
<span class="badge text-bg-dark rounded-pill position-absolute top-0 start-0 m-3">New</span>
<button type="button" class="pc-fav btn btn-light rounded-circle position-absolute top-0 end-0 m-3 p-0" aria-pressed="false" aria-label="Save to wishlist">
<svg viewBox="0 0 24 24" width="20" height="20" 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 21.3l7.8-7.8 1-1.1a5.5 5.5 0 0 0 0-7.8z"/></svg>
</button>
</div>
<div class="p-4 p-md-5 col-md-6 d-flex flex-column justify-content-center">
<p class="wdw-eyebrow mb-1">Timepieces</p>
<h1 class="h4 fw-bold mb-2 text-body-emphasis">Yail Smart Watch</h1>
<div class="d-flex align-items-center gap-2 small mb-3">
<span class="text-warning d-inline-flex gap-1" aria-hidden="true"><svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor" aria-hidden="true"><path d="M12 2.5l2.9 6.1 6.6.8-4.9 4.6 1.3 6.6L12 17.3 6.1 20.6l1.3-6.6L2.5 9.4l6.6-.8z"/></svg><svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor" aria-hidden="true"><path d="M12 2.5l2.9 6.1 6.6.8-4.9 4.6 1.3 6.6L12 17.3 6.1 20.6l1.3-6.6L2.5 9.4l6.6-.8z"/></svg><svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor" aria-hidden="true"><path d="M12 2.5l2.9 6.1 6.6.8-4.9 4.6 1.3 6.6L12 17.3 6.1 20.6l1.3-6.6L2.5 9.4l6.6-.8z"/></svg><svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor" aria-hidden="true"><path d="M12 2.5l2.9 6.1 6.6.8-4.9 4.6 1.3 6.6L12 17.3 6.1 20.6l1.3-6.6L2.5 9.4l6.6-.8z"/></svg><svg viewBox="0 0 24 24" width="16" height="16" fill="currentColor" aria-hidden="true"><path d="M12 2.5l2.9 6.1 6.6.8-4.9 4.6 1.3 6.6L12 17.3 6.1 20.6l1.3-6.6L2.5 9.4l6.6-.8z"/></svg></span>
<span class="wdw-muted"><span class="visually-hidden">Rated </span>4.9<span class="visually-hidden"> out of 5</span> (212 reviews)</span>
</div>
<div class="d-flex align-items-baseline flex-wrap gap-2 mb-3">
<p class="h3 fw-bolder mb-0 text-body-emphasis">$299</p>
<s class="wdw-muted"><span class="visually-hidden">Was </span>$349</s>
<span class="badge bg-success-subtle text-success-emphasis rounded-pill">Save 15%</span>
</div>
<p class="wdw-muted small mb-3">A 38 mm case, bright always-on display and a soft strap that fits most wrists.</p>
<fieldset class="mb-3">
<legend class="small fw-semibold mb-2 float-none w-auto">Colour: <span id="pcColourName" class="fw-normal wdw-muted">Cloud</span></legend>
<div class="d-flex gap-2">
<input type="radio" class="btn-check" name="pcColour" id="pcC1" value="Cloud" checked>
<label class="pc-swatch rounded-circle" for="pcC1" style="--sw:#e5e7eb"><span class="visually-hidden">Cloud</span></label>
<input type="radio" class="btn-check" name="pcColour" id="pcC2" value="Indigo">
<label class="pc-swatch rounded-circle" for="pcC2" style="--sw:#4f46e5"><span class="visually-hidden">Indigo</span></label>
<input type="radio" class="btn-check" name="pcColour" id="pcC3" value="Graphite">
<label class="pc-swatch rounded-circle" for="pcC3" style="--sw:#374151"><span class="visually-hidden">Graphite</span></label>
</div>
</fieldset>
<fieldset class="mb-4">
<legend class="small fw-semibold mb-2 float-none w-auto">Strap size</legend>
<div class="d-flex gap-2">
<input type="radio" class="btn-check" name="pcSize" id="pcS1" checked>
<label class="btn btn-outline-secondary rounded-pill px-3" for="pcS1">S/M</label>
<input type="radio" class="btn-check" name="pcSize" id="pcS2">
<label class="btn btn-outline-secondary rounded-pill px-3" for="pcS2">M/L</label>
</div>
</fieldset>
<div class="d-grid gap-2">
<button type="button" class="btn btn-primary rounded-pill" id="pcAdd">
<svg class="pc-ico-cart" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 6h15l-1.5 9H7.5zM6 6 5 3H2M9 20h.01M18 20h.01"/></svg>
<svg class="pc-ico-check d-none" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>
<span>Add to cart</span>
</button>
<a href="#" class="btn btn-outline-secondary text-body-emphasis rounded-pill">View details</a>
</div>
<p class="small text-success-emphasis mb-0 mt-3 d-flex align-items-center gap-2">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>
In stock · free delivery in 2–3 days
</p>
<p class="visually-hidden" id="pcLive" role="status" aria-live="polite"></p>
</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 */
.pc-media { background: var(--bs-primary-bg-subtle); aspect-ratio: 1 / 1; overflow: hidden; padding: 1.25rem; }
.pc-media img { width: 100%; height: 100%; object-fit: cover; border-radius: 1rem; box-shadow: var(--wdw-shadow-sm); transition: transform .5s; }
.pc:hover .pc-media img { transform: scale(1.03); }
.pc-fav { width: 2.75rem; height: 2.75rem; min-height: 0; color: var(--bs-dark); background: var(--bs-white); border-color: transparent; box-shadow: var(--wdw-shadow-sm); }
.pc-fav:hover { color: var(--bs-dark); background: var(--bs-white); }
.pc-fav[aria-pressed="true"] { color: var(--bs-danger); }
.pc-fav[aria-pressed="true"] svg { fill: currentColor; }
.pc-swatch { width: 2.75rem; height: 2.75rem; background: var(--sw); border: 2px solid var(--bs-border-color); box-shadow: inset 0 0 0 3px var(--bs-body-bg); cursor: pointer; }
.btn-check:checked + .pc-swatch { border-color: var(--bs-primary); }
.btn-check:focus-visible + .pc-swatch, .btn-check:focus-visible + .btn { outline: 3px solid var(--bs-primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .pc-media img { transition: none; } }
@media (min-width: 768px) { .pc-media { aspect-ratio: auto; min-height: 520px; } .pc-media img { position: absolute; inset: 1.25rem; width: calc(100% - 2.5rem); height: calc(100% - 2.5rem); } }
(function initProductCard() {
const fav = document.querySelector('.pc-fav');
if (fav) fav.addEventListener('click', function () {
fav.setAttribute('aria-pressed', fav.getAttribute('aria-pressed') !== 'true');
});
})();
(function initProductOptions() {
const name = document.getElementById('pcColourName');
document.querySelectorAll('input[name="pcColour"]').forEach(function (r) {
r.addEventListener('change', function () { if (name) name.textContent = r.value; });
});
})();
(function initAddToCart() {
const add = document.getElementById('pcAdd');
const live = document.getElementById('pcLive');
if (!add) return;
const label = add.querySelector('span');
const cart = add.querySelector('.pc-ico-cart');
const check = add.querySelector('.pc-ico-check');
add.addEventListener('click', function () {
add.disabled = true;
label.textContent = 'Added';
cart.classList.add('d-none'); check.classList.remove('d-none');
if (live) live.textContent = 'Added to cart';
setTimeout(function () {
add.disabled = false;
label.textContent = 'Add to cart';
cart.classList.remove('d-none'); check.classList.add('d-none');
if (live) live.textContent = '';
}, 1800);
});
})();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.