Compares two images (or any content) with a draggable slider, or a crossfade.
Provide two layers via the before and after slots — any content works
(images, or plain markup as shown here). Drag the divider to compare.
<nana-image-comparer style="width:100%;max-width:26rem">
<div slot="before" style="aspect-ratio:3/2;display:grid;place-items:center;background:#1f6feb;color:#fff;font-weight:600;font-size:1.25rem">Before</div>
<div slot="after" style="aspect-ratio:3/2;display:grid;place-items:center;background:#f59e0b;color:#111;font-weight:600;font-size:1.25rem">After</div>
</nana-image-comparer>
npm install @nana-tec/ui-components
import "@nana-tec/ui-components/image-comparer";
<img slot="before" src="/before.jpg" alt="Before" />
<img slot="after" src="/after.jpg" alt="After" />
Set variant="fade" to crossfade between the two layers as you drag, instead
of the default clip slider.
<nana-image-comparer variant="fade" style="width:100%;max-width:26rem">
<div slot="before" style="aspect-ratio:3/2;display:grid;place-items:center;background:#1f6feb;color:#fff;font-weight:600;font-size:1.25rem">Before</div>
<div slot="after" style="aspect-ratio:3/2;display:grid;place-items:center;background:#f59e0b;color:#111;font-weight:600;font-size:1.25rem">After</div>
</nana-image-comparer>
Properties
| Property | Attribute | Type | Default | Description |
|---|
position | — | number | 50 | Divider position, 0–100 |
variant | — | ImageComparerVariant | 'slider' | Slider (clip) or fade (crossfade) |
Events
| Event | Description |
|---|
nana-change | Fired when the position changes (`detail.position`) |
Slots
| Slot | Description |
|---|
before | The "before" layer (overlaid / clipped) |
after | The "after" layer (base, sets the size) |
CSS parts
| Part | Description |
|---|
::part(base) | The container |
::part(handle) | The drag handle |
CSS custom properties
| Property | Description |
|---|
--nana-image-comparer-divider | Handle / divider colour |
| Event | Type | Description |
|---|
nana-change | CustomEvent | Fired when the position changes (detail.position) |
| Slot | Description |
|---|
before | The “before” layer (overlaid / clipped) |
after | The “after” layer (base, sets the size) |
| Variable | Default | Description |
|---|
--nana-image-comparer-divider | — | Handle / divider colour |
| Part | Description |
|---|
base | The container |
handle | The drag handle |
- Keyboard accessible
- Screen-reader labels
- Focus-visible states
- ARIA roles and states
- WCAG 2.2 AA contrast
Explore Image Comparer interactively Every state, prop, and edge case — with live controls — in Storybook.
View in Storybook