Product Color Swatches
Color swatch buttons that update a large preview and label.
Requires Bootstrap 5. Add the CDN tags below to your page (styles in
<head>, scripts before </body>). The downloaded file already includes them.<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script><div class="card border-0 shadow-sm" style="max-width:300px"><div class="card-body">
<h6 class="fw-bold mb-2">Select color</h6>
<div class="d-flex gap-2 mb-3" id="cpSw"><button class="btn rounded-circle p-0 border" data-c="#0d6efd" style="width:32px;height:32px;background:#0d6efd"></button><button class="btn rounded-circle p-0 border" data-c="#16a34a" style="width:32px;height:32px;background:#16a34a"></button><button class="btn rounded-circle p-0 border" data-c="#ff477e" style="width:32px;height:32px;background:#ff477e"></button></div>
<div class="rounded-3" id="cpBig" style="height:80px;background:#0d6efd;transition:.2s"></div>
<small class="text-secondary" id="cpLab">Selected: Blue</small>
</div></div>var names={'#0d6efd':'Blue','#16a34a':'Green','#ff477e':'Pink'};
document.querySelectorAll('#cpSw [data-c]').forEach(function(b){b.onclick=function(){document.getElementById('cpBig').style.background=b.dataset.c;document.getElementById('cpLab').textContent='Selected: '+names[b.dataset.c]}});Free to use.This component uses Bootstrap 5 (linked above). Copy any file, or download a ready-to-open .html page with the CDN links already included.