<div class="product-card">
<div class="image-box">
<img id="productImg" src="https://placehold.co/400x400/3b82f6/ffffff?text=Blue+Shirt" alt="Product">
</div>
<div class="details">
<h3>Classic T-Shirt</h3>
<p>$29.99</p>
<div class="colors">
<span class="swatch active" data-color="#3b82f6" data-img="https://placehold.co/400x400/3b82f6/ffffff?text=Blue+Shirt"></span>
<span class="swatch" data-color="#ef4444" data-img="https://placehold.co/400x400/ef4444/ffffff?text=Red+Shirt"></span>
<span class="swatch" data-color="#10b981" data-img="https://placehold.co/400x400/10b981/ffffff?text=Green+Shirt"></span>
<span class="swatch" data-color="#f59e0b" data-img="https://placehold.co/400x400/f59e0b/ffffff?text=Yellow+Shirt"></span>
</div>
<button>Add to Cart</button>
</div>
</div>
Back to Snippets
Product Card with Color Swatches JS
Let users customize their choice with this interactive product card. Clicking a color swatch updates the product image instantly, which helps customers visualize what they are buying without reloading the page.
458