Image Compare
Before-and-after comparison: two stacked images and a divider you drag to reveal one over the other.
<arc-image-compare>Overview
Image Compare stacks two images and shows the before slot over the after slot up to a divider you drag. The reveal is a CSS clip driven by position (0 to 100, default 50), so the component server-renders at its starting position and never measures the images. Both slots take a plain <img> or an arc-image. The two images need the same aspect ratio, because the top layer is cropped to cover the frame.
The divider's round handle is also the keyboard control: a focusable role="slider" that moves by 1 with the arrow keys, by 10 with Shift, and to either end with Home and End. Dragging fires arc-input on every move and arc-change once on release.
orientation names the axis the divider moves along: horizontal (the default) slides a vertical line left and right, and vertical slides a horizontal line up and down. Position 0 is the inline-start edge, so the control mirrors in right-to-left documents.
Guidelines
Do
- Use two images of the same subject at the same aspect ratio
- Set `before-label` and `after-label` when the images don't make the direction of the edit obvious
- Give the handle a `label` that says what's being compared, for screen readers
- Use `arc-input` for cheap live readouts and `arc-change` for anything expensive or saved
Don't
- Don't use it for unrelated images. Use Carousel
- Don't compare text or code revisions with it. A rendered diff shows those changes exactly
- Don't start `position` near 0 or 100. With one image almost hidden, people won't see there's anything to drag
Features
- A drag can start anywhere on the frame
- `before-label` and `after-label` add caption chips in the corners of each image
Preview
Usage
Image Compare is in the marketing group, so the default @arclux/arc-ui entry point doesn't include it. Import it from@arclux/arc-ui/marketing or from its own subpath,@arclux/arc-ui/image-compare.
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-image-compare
label="Color grade comparison"
before-label="Original"
after-label="Graded"
position="50"
>
<img slot="before" src="/photos/valley-raw.jpg" alt="River valley, unedited" />
<img slot="after" src="/photos/valley-graded.jpg" alt="River valley, color graded" />
</arc-image-compare>
<!-- Vertical divider motion -->
<arc-image-compare orientation="vertical" label="Sky replacement">
<img slot="before" src="/photos/sky-raw.jpg" alt="Original sky" />
<img slot="after" src="/photos/sky-replaced.jpg" alt="Replaced sky" />
</arc-image-compare>import { ImageCompare } from '@arclux/arc-ui-react';
export default function Example() {
return (
<ImageCompare
label="Color grade comparison"
beforeLabel="Original"
afterLabel="Graded"
onArcChange={(e) => console.log('committed at', e.detail.value)}
>
<img slot="before" src="/photos/valley-raw.jpg" alt="River valley, unedited" />
<img slot="after" src="/photos/valley-graded.jpg" alt="River valley, color graded" />
</ImageCompare>
);
}<script setup>
import { ImageCompare } from '@arclux/arc-ui-vue';
</script>
<template>
<ImageCompare label="Color grade comparison" before-label="Original" after-label="Graded">
<img slot="before" src="/photos/valley-raw.jpg" alt="River valley, unedited" />
<img slot="after" src="/photos/valley-graded.jpg" alt="River valley, color graded" />
</ImageCompare>
</template><script>
import { ImageCompare } from '@arclux/arc-ui-svelte';
</script>
<ImageCompare label="Color grade comparison" before-label="Original" after-label="Graded">
<img slot="before" src="/photos/valley-raw.jpg" alt="River valley, unedited" />
<img slot="after" src="/photos/valley-graded.jpg" alt="River valley, color graded" />
</ImageCompare>import { Component } from '@angular/core';
import { ImageCompare } from '@arclux/arc-ui-angular';
@Component({
imports: [ImageCompare],
template: `
<arc-image-compare label="Color grade comparison" before-label="Original" after-label="Graded">
<img slot="before" src="/photos/valley-raw.jpg" alt="River valley, unedited" />
<img slot="after" src="/photos/valley-graded.jpg" alt="River valley, color graded" />
</arc-image-compare>
`,
})
export class ComparisonComponent {}import { ImageCompare } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<ImageCompare label="Color grade comparison" beforeLabel="Original" afterLabel="Graded">
<img slot="before" src="/photos/valley-raw.jpg" alt="River valley, unedited" />
<img slot="after" src="/photos/valley-graded.jpg" alt="River valley, color graded" />
</ImageCompare>
);
}import { ImageCompare } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<ImageCompare label="Color grade comparison" beforeLabel="Original" afterLabel="Graded">
<img slot="before" src="/photos/valley-raw.jpg" alt="River valley, unedited" />
<img slot="after" src="/photos/valley-graded.jpg" alt="River valley, color graded" />
</ImageCompare>
);
}API
before-labelstring''- Optional caption for the before layer, rendered as a floating chip in the start corner.
after-labelstring''- Optional caption for the after layer, rendered as a floating chip in the end corner.
labelstring''- Accessible name for the divider handle, announced as the slider label.
positionnumber50- Divider position as a percentage, 0 to 100. 0 shows only the after layer, 100 only the before layer. Clamped, reflected, and updated as the user drags.
orientation'horizontal' | 'vertical''horizontal'- Axis the divider moves along.
horizontal(default) moves a vertical divider line left-right;verticalmoves a horizontal line up-down.
Events
arc-inputdetail:{ value: number }- Fired continuously while dragging (every pointer move) and on each keyboard nudge.
valueis the position, 0-100. Use for live readouts. arc-changedetail:{ value: number }- Fired once when the position commits: on pointer release, or with each keyboard nudge. Use for persisting the position.
See also
- ImageImage with a shimmer skeleton while it loads, a fade-in, an error fallback and aspect ratio presets.
- CarouselShows its children one at a time as full-width slides in a scroll-snapping strip.
- Aspect RatioA box that holds its content to a fixed width-to-height ratio.
- Image CropperCrop-before-upload control: drag and resize a crop rectangle, lock its aspect ratio, zoom, and export the crop at the image's natural resolution.