Before/After Slider
A draggable divider revealing a before/after image comparison.
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 overflow-hidden" style="max-width:320px"><div class="position-relative" id="baWrap" style="height:200px;user-select:none">
<div class="position-absolute w-100 h-100" style="background:linear-gradient(135deg,#1a1f36,#3a4a6b)"></div>
<div class="position-absolute h-100 overflow-hidden" id="baTop" style="width:50%;background:linear-gradient(135deg,#ff7a18,#ff477e)"></div>
<div class="position-absolute top-0 h-100 bg-white" id="baLine" style="left:50%;width:3px;cursor:ew-resize"><span class="position-absolute top-50 start-50 translate-middle bg-white rounded-circle d-grid" style="width:30px;height:30px;place-items:center">⇄</span></div>
</div></div>var wrap=document.getElementById('baWrap'),top=document.getElementById('baTop'),line=document.getElementById('baLine'),drag=false;
function move(x){var r=wrap.getBoundingClientRect(),p=Math.max(0,Math.min(1,(x-r.left)/r.width));top.style.width=(p*100)+'%';line.style.left=(p*100)+'%'}
line.addEventListener('mousedown',function(){drag=true});
window.addEventListener('mouseup',function(){drag=false});
wrap.addEventListener('mousemove',function(e){if(drag)move(e.clientX)});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.