Skip to content
Nana UI

Image Comparer

View .md Download

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.

Before
After
Terminal window
npm install @nana-tec/ui-components
import "@nana-tec/ui-components/image-comparer";
<nana-image-comparer>
<img slot="before" src="/before.jpg" alt="Before" />
<img slot="after" src="/after.jpg" alt="After" />
</nana-image-comparer>

Set variant="fade" to crossfade between the two layers as you drag, instead of the default clip slider.

Before
After

Properties

PropertyAttributeTypeDefaultDescription
positionnumber50Divider position, 0–100
variantImageComparerVariant'slider'Slider (clip) or fade (crossfade)

Events

EventDescription
nana-changeFired when the position changes (`detail.position`)

Slots

SlotDescription
beforeThe "before" layer (overlaid / clipped)
afterThe "after" layer (base, sets the size)

CSS parts

PartDescription
::part(base)The container
::part(handle)The drag handle

CSS custom properties

PropertyDescription
--nana-image-comparer-dividerHandle / divider colour
EventTypeDescription
nana-changeCustomEventFired when the position changes (detail.position)
SlotDescription
beforeThe “before” layer (overlaid / clipped)
afterThe “after” layer (base, sets the size)
VariableDefaultDescription
--nana-image-comparer-dividerHandle / divider colour
PartDescription
baseThe container
handleThe 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