Before/after slider
Before after slider · Image comparison slider · Confronto immagini · Comparador de imágenes · Antes y después · Slider di confronto
Two stacked images split by a vertical line with a round handle. Dragging it reveals more of one or the other, showing a restoration, a retouch or a before and after in a single frame.
- Era
- 2010 – today
- Origin
- Web (globale)
- Use
- Mainstream
Live demo
View code
<div class="cmp"><div class="img a"></div><div class="img b"></div><span class="l1">PRIMA</span><span class="l2">DOPO</span><div class="ln"><i>◀ ▶</i></div></div>
<script>
const c=document.querySelector('.cmp');let t=0,u=null;c.addEventListener('pointermove',e=>{const r=c.getBoundingClientRect();u=(e.clientX-r.left)/r.width});c.addEventListener('pointerleave',()=>u=null);
const go=()=>{t+=.012;const p=u??(.5+Math.sin(t)*.32);c.style.setProperty('--p',(p*100)+'%');if(matchMedia('(prefers-reduced-motion: no-preference)').matches||u!==null)requestAnimationFrame(go)};go();
</script> body{background:#1E1E1E;display:grid;place-items:center;font-family:Inter,sans-serif}
.cmp{--p:50%;position:relative;width:560px;max-width:94vw;height:280px;border-radius:10px;overflow:hidden;cursor:ew-resize}
.img{position:absolute;inset:0;background:linear-gradient(transparent 62%,#555 62%),linear-gradient(90deg,transparent 18%,#777 18% 22%,transparent 22% 78%,#777 78% 82%,transparent 82%),linear-gradient(transparent 30%,#8d8d8d 30% 34%,transparent 34%),linear-gradient(#bfbfbf,#9a9a9a)}
.a{filter:sepia(.3) contrast(.8)}
.b{clip-path:inset(0 0 0 var(--p));background:repeating-linear-gradient(90deg,#E8B04B 0 28px,#fff 28px 56px) 0 26%/100% 10% no-repeat,linear-gradient(transparent 62%,#6E8C9C 62%),linear-gradient(90deg,transparent 18%,#2f5d50 18% 22%,transparent 22% 78%,#2f5d50 78% 82%,transparent 82%),linear-gradient(#cfe7f2,#f6e7cf)}
span{position:absolute;top:12px;font-size:11px;font-weight:600;letter-spacing:.12em;color:#fff;background:#0007;padding:4px 8px;border-radius:4px}.l1{left:12px}.l2{right:12px}
.ln{position:absolute;top:0;bottom:0;left:var(--p);width:3px;margin-left:-1.5px;background:#fff;box-shadow:0 0 8px #0006}
.ln i{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:44px;height:44px;border-radius:50%;background:#fff;display:grid;place-items:center;font-style:normal;font-size:10px;color:#1E1E1E;box-shadow:0 2px 8px #0005} Characteristics
- White vertical line with a round handle and ◀ ▶ arrows
- «Before» and «After» labels in the corners
- Smooth clipping of the top image
- Dragged with a finger, the mouse or the arrow keys
- The two images are perfectly aligned
Palette
Click a swatch to copy it
Typography
Headings · Inter Before/after slider
Body · Inter Two stacked images split by a vertical line with a round handle. Dragging it reveals more of one or the other, showing a restoration, a retouch or a before and after in a single frame.
Motion
- Easing
segue il puntatore; ease-out 300 ms quando si clicca un punto- Typical duration
- continua durante il trascinamento
- Techniques
- clip-path inset, input type range sovrapposto, pointer events, <img-comparison-slider> web component, aria-valuenow per l'accessibilità
Accessibility (reduced motion)
The line only moves where the user drags it, with no automatic animation.
Prompt for your agent
Copy and paste into your prompt to have an agent or image generator reproduce this style.
For web pages and UI
Design the web page or interface in this style: Before/after slider (Before after slider, Image comparison slider). Two stacked images split by a vertical line with a round handle. Dragging it reveals more of one or the other, showing a restoration, a retouch or a before and after in a single frame. Characteristics: White vertical line with a round handle and ◀ ▶ arrows, «Before» and «After» labels in the corners, Smooth clipping of the top image, Dragged with a finger, the mouse or the arrow keys, The two images are perfectly aligned. Palette: #FFFFFF, #1E1E1E, #E8B04B, #6E8C9C. Typography: headings in Inter, body text in Inter (Google Fonts or equivalents). Mood: clean, rational, tactile. Motion: easing segue il puntatore; ease-out 300 ms quando si clicca un punto, typical duration continua durante il trascinamento; techniques: clip-path inset, input type range sovrapposto, pointer events, <img-comparison-slider> web component, aria-valuenow per l'accessibilità. With prefers-reduced-motion: The line only moves where the user drags it, with no automatic animation. References: Siti di fotoritocco e restauro, Pagine prodotto di app fotografiche, Giornalismo (prima e dopo di eventi).
Relations
Similar to
Contrasts with
References
- Siti di fotoritocco e restauro
- Pagine prodotto di app fotografiche
- Giornalismo (prima e dopo di eventi)