04.42 · Micro-Interactions

Before/After Slider

Drag a line across two pictures to compare them. Best for photo edits.

Drag it

Drag the line, or press Show me.

Try it

Change a setting, then drag the line or press Show me.

Split

Which way the line runs.

Handle

A knob tells people they can drag.

Before and After fade as the line covers them.

Copy the prompt

Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.

Add a before-and-after slider to [the two pictures you want to compare]. Stack the pictures exactly on top of each other and show the top one only up to a dividing line with a handle, so each side of the line shows one picture. Dragging on the pictures moves the line, and a tap jumps it there. Uncover the top picture with a clip or a sliding window, never by resizing it, so neither picture moves or squeezes. Use pointer events for mouse and touch, keep page scrolling free on phones, and let the arrow keys move the handle. If the visitor has reduced motion turned on, move the line without gliding. Match the settings listed below.

Replace the words in brackets with your own element. Your settings are added at the end.

Free and open source. If this helped, a star on GitHub helps other people find it.

Star on GitHub

What it is

The full explanation is in README.md.

Good for

  • Photo edits
  • Redesigns
  • Renovations
  • Product upgrades

Avoid on

  • Small thumbnails
  • Unrelated pictures