Skip to content
Nana UI

Data Display & Media

Image Comparer

Compares two images (or any content) with a draggable slider, or a crossfade.

View .md Download

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
npm install @nana-tec/ui-components
import "@nana-tec/ui-components/image-comparer";
<nana-image-comparer>
<img slot="before" src="/compare-before.svg" alt="Before" />
<img slot="after" src="/compare-after.svg" 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

min and max are percentages the divider must stay between, so neither image can be hidden entirely. They hold against dragging, the arrow keys, and Home and End alike.

Before After

With neither set the divider runs the whole frame, which is how it has always behaved.

Properties

PropertyAttributeTypeDefaultDescription
maxmaxnumber100Most of the first image the divider may leave showing, 0–100.
minminnumber0Least of the first image the divider may leave showing, 0–100.
positionpositionnumber50Divider position, 0–100
variantvariantImageComparerVariant'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
--nana-image-comparer-radiusCorner radius of the framed images
EventTypeDescription
nana-changeCustomEventFired when the position changes (detail.position)
SlotDescription
beforeThe “before” layer (overlaid / clipped)
afterThe “after” layer (base, sets the size)
VariableDescription
--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