Limited Stock Bar
A scarcity bar that decreases stock with each purchase click.
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:320px"><div class="card-body">
<div class="d-flex justify-content-between small mb-1"><span class="fw-semibold">Limited stock</span><span class="text-danger" id="stLeft">7 left</span></div>
<div class="progress mb-2" style="height:8px"><div class="progress-bar bg-danger" id="stBar" style="width:14%"></div></div>
<button class="btn btn-primary btn-sm w-100" id="stBuy">Buy now</button>
</div></div>var left=7,total=50;
document.getElementById('stBuy').onclick=function(){if(left>0){left--;document.getElementById('stLeft').textContent=left+' left';document.getElementById('stBar').style.width=(left/total*100)+'%';if(left===0){this.disabled=true;this.textContent='Sold out';document.getElementById('stLeft').textContent='Out of stock'}}};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.