Data Display

ImageCompare

Compares two screenshots side by side in panes that scroll together, or overlaid with a wipe the reader drags or steps with a slider.

import { ImageCompare } from '@lostgradient/cinder';
image-compare
01

Overview

Reference usage

ImageCompare compares two screenshots of the same screen: side by side in panes that scroll together, or overlaid with a wipe the reader drags.

Usage

svelte
<script lang="ts">
  import { ImageCompare } from '@lostgradient/cinder';

  const before = {
    src: '/captures/checkout-round-2.png',
    alt: 'Checkout form, round 2',
    label: 'Round 2',
    caption: 'previous version',
  };
  const after = {
    src: '/captures/checkout-round-3.png',
    alt: 'Checkout form, round 3',
    label: 'Round 3',
    caption: 'this round',
  };
</script>

<ImageCompare {before} {after} />

Side by side, each image is a figure captioned by its label and caption. The panes scroll together by pixel offset, so two screenshots of the same width stay row for row, and they stack once the container is too narrow for two columns. Images show at their natural size.

In the wipe mode the two overlap: before shows up to a divider and after beyond it. The reader drags the round handle with a pointer, or uses the "Wipe position" slider under the frame, whose ends and value text name the two images by label. position is bindable, from 0 (all after) to 1 (all before). offset shifts before by whole pixels to line the two up, and applies only in the wipe; build the nudge buttons from Button.

svelte
<script lang="ts">
  import { Button, ImageCompare } from '@lostgradient/cinder';

  let position = $state(0.5);
  let offset = $state({ x: 0, y: 0 });
</script>

<ImageCompare
  mode="wipe"
  bind:position
  bind:offset
  before={{ src: '/captures/round-2.png', alt: 'Round 2 capture', label: 'Round 2' }}
  after={{ src: '/captures/round-3.png', alt: 'Round 3 capture', label: 'Round 3' }}
/>
<Button onclick={() => (offset = { ...offset, x: offset.x - 1 })}>Nudge round 2 left</Button>

The page owns the mode switch (a SegmentedControl) and passes mode.

Live preview

Side by side

Round 2 previous version
Checkout form, round 2
Round 3 this round
Checkout form, round 3

02

When to use

Use when
  • Checking what changed between two versions of the same screen, such as two review rounds.
Avoid when
03

Examples

Side by side

Two captioned panes that scroll together, so two screenshots of one screen stay row for row.

Wipe

The two images overlap; drag the handle or use the slider to move the divider between them.

04

Props

Props for image-compare
Name
Type
Default
Description
before required { /** The image's URL. */ src: string; /** The image's text alternative. */ alt: string; /** A short name for the version, such as "Round 2". The wipe…
Show full type { /** The image's URL. */ src: string; /** The image's text alternative. */ alt: string; /** A short name for the version, such as "Round 2". The wipe's slider and its value text use it. */ label: string; /** Words after the label in the side-by-side caption, such as "previous version". */ caption?: string; }
The earlier image: the start pane side by side, the clipped layer in the wipe.
after required { /** The image's URL. */ src: string; /** The image's text alternative. */ alt: string; /** A short name for the version, such as "Round 2". The wipe…
Show full type { /** The image's URL. */ src: string; /** The image's text alternative. */ alt: string; /** A short name for the version, such as "Round 2". The wipe's slider and its value text use it. */ label: string; /** Words after the label in the side-by-side caption, such as "previous version". */ caption?: string; }
The later image: the end pane side by side, the full layer under the wipe.
mode 'side-by-side' | 'wipe' 'side-by-side' side-by-side shows the two in panes that scroll together, stacked when the container is narrow. wipe overlays them, with before shown up to a divider the reader drags.
position bindable number 0.5 The wipe's position, from 0 (all after) to 1 (all before): the share of the frame's width that shows before. Bindable. Values outside 0 to 1 are clamped.
offset bindable { x: number; y: number } How far before is shifted, in pixels, to line it up with after in the wipe. Side-by-side panes are never shifted. Bindable.