Skip to main content
CleanImg Online
All articles

How to Align Two Images for a Before-and-After Slider

Measure landmarks on a real backpack pair, then set up both layers to share the same geometry.

Green backpack on a table before background removal

A before-and-after slider should let the eye stay on one object while the edit changes around it. If the subject shifts or scales as you drag the handle, visitors have to separate the edit from a change in framing. Build both states on one canvas and compare them before creating the slider.

The backpack pair used in this guide

The supplied before image and transparent after image are both 1200 × 675. To check their placement, we measured the bounding box of strongly green product pixels. The left, top, right, and bottom extremes were approximately x 341, y 14, x 850, and y 623 in both files. This is a quick position check for the green fabric. A visual inspection of the straps, base, and handle still matters because a shared bounding box can miss changes inside it.

The same green backpack on a transparent canvas after background removal
After state on a light preview backing. The transparent PNG retains the 1200 × 675 canvas.

Build the pair from a single source

Decide on the crop while the original is open. Leave room around the subject, including thin features such as straps and handles. Save the crop as the before state. Create the after state on the same canvas. If an editor exports a smaller result, put it in a layer over the before image and compare coordinates before saving a final pair. If the shape changes significantly or important detail is lost, go back to the original and produce another cutout.

Use three landmarks that are far apart. On the backpack, start with the top of the handle, the lower corner where it meets the table, and a point on the opposite strap. Turn the top layer on and off. If all three points move in the same direction by the same amount, adjust position. If the distance between points changes, correct the scale with proportions locked. Rotation becomes easier to spot when two points along a straight seam align at one end and separate at the other.

After you have lined up the layers, save both states with identical dimensions. Check that transparent padding is still present in the cutout. Some crop and export options automatically trim transparent pixels. A trimmed PNG can look correct alone and jump in the shared slider.

Give the two layers identical display geometry

Put both images inside one positioned container with a fixed aspect ratio. Apply the same dimensions and fitting rules. The top image can be revealed with a clipping boundary so the content underneath keeps its full size as the handle moves. Changing the width of the top image itself can rescale it, which is especially noticeable near the edges. MDN’s reference for CSS clipping

.comparison { position: relative; aspect-ratio: 16 / 9; }
.comparison img { position: absolute; inset: 0; width: 100%;
                  height: 100%; object-fit: contain; }
.comparison .after { clip-path: inset(0 calc(100% - var(--reveal, 50%)) 0 0); }

This snippet gives both layers the same geometry and reveals the after image over the left portion of the container. Put the control on a labeled range input and update the reveal percentage from its value. Test the keyboard controls through the full range, and offer links or labeled static views if the interaction is unavailable. If the after layer has transparent pixels, give that layer or an enclosing layer the intended preview backing. Otherwise the original backdrop can show through and undermine the comparison.

Check the smallest view before publishing

Drag the handle across a landmark at desktop size, then repeat on a narrow phone viewport. Watch for a seam that jumps at the dividing line. Look at the extremes of the control and confirm users can see both states completely. If one image is cropped differently on mobile, look for a separate sizing rule or responsive source applied to just one layer.

Keep the originals with clear names and retain the transparent export. A later edit can reuse the same frame and landing positions, which makes subsequent comparisons much easier to check.