Pricing Monthly/Yearly Toggle
A pricing pair whose prices switch between monthly and yearly.
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="text-center" style="max-width:340px">
<div class="btn-group btn-group-sm mb-3"><button class="btn btn-primary" id="ptM">Monthly</button><button class="btn btn-outline-primary" id="ptY">Yearly</button></div>
<div class="row g-2"><div class="col-6"><div class="card border-0 shadow-sm h-100"><div class="card-body p-3"><h6 class="text-secondary small text-uppercase">Basic</h6><div class="h3 fw-bold" data-m="$9" data-y="$86">$9</div><button class="btn btn-outline-primary btn-sm w-100">Choose</button></div></div></div>
<div class="col-6"><div class="card border-primary shadow-sm h-100"><div class="card-body p-3"><h6 class="text-secondary small text-uppercase">Pro</h6><div class="h3 fw-bold" data-m="$29" data-y="$278">$29</div><button class="btn btn-primary btn-sm w-100">Choose</button></div></div></div></div>
</div>var els=document.querySelectorAll('[data-m]'),m=document.getElementById('ptM'),y=document.getElementById('ptY');
m.onclick=function(){m.className='btn btn-primary';y.className='btn btn-outline-primary';els.forEach(function(e){e.textContent=e.dataset.m})};
y.onclick=function(){y.className='btn btn-primary';m.className='btn btn-outline-primary';els.forEach(function(e){e.textContent=e.dataset.y})};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.