Toggle Button Group
A multi-select button group that summarizes the chosen options.
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">
<label class="form-label small fw-semibold d-block">Notify me about</label>
<div class="btn-group flex-wrap" role="group" id="tgWrap"><input type="checkbox" class="btn-check" id="tg1"><label class="btn btn-outline-primary btn-sm" for="tg1">News</label><input type="checkbox" class="btn-check" id="tg2"><label class="btn btn-outline-primary btn-sm" for="tg2">Offers</label><input type="checkbox" class="btn-check" id="tg3"><label class="btn btn-outline-primary btn-sm" for="tg3">Updates</label></div>
<small class="text-secondary d-block mt-2" id="tgOut">None selected</small>
</div></div>var boxes=document.querySelectorAll('#tgWrap input'),out=document.getElementById('tgOut');
boxes.forEach(function(b){b.onchange=function(){var sel=[].filter.call(boxes,function(x){return x.checked}).map(function(x){return x.nextElementSibling.textContent});out.textContent=sel.length?sel.join(', '):'None selected'}});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.