Skip to content

Comparison

Free

Two versions of one picture in one frame. Drag the line, swipe, or use the arrow keys to compare before and after.

  • Base UI
  • React 19
  • Tailwind CSS 4

Added Nov 9, 2026 · MIT + Commons Clause

Playground

Loading the preview

Props

Put the edited image in ComparisonAfter, the original in ComparisonBefore, and add the handle that people drag.

The sample also uses Image. One command adds them with this item:

color-grade.tsx

Comparison

<div>
PropTypeDefaultDescription
valuenumber—The share of the before, 0–100 (controlled).
defaultValuenumber50The share of the before at the start, 0–100 (uncontrolled). Default 50.
onValueChange—Runs on every change, with the new share of the before and why it changed: the Base UI Slider reasons (keyboard, input-change), plus the ones of the pointer layer of this component: track-press (a mouse press on the frame), drag, swipe (a finger across the frame), tap (a finger tap on the frame), and hover.
onValueCommitted—Runs when a change ends: a key press, a pointer release, a tap. The same reasons; hover never commits (it has no end). The details are { reason, event } only: a change cannot be canceled from here (make the Comparison controlled to keep a value).
orientation"horizontal""vertical""horizontal"horizontal (default): a vertical divider, the before on the start side. vertical: the before on top.
interaction"drag""handle""hover""drag"How a pointer moves the divider. Keys and touch work the same in every mode. - drag (default): a press anywhere on the frame moves the divider to the pointer, and the drag goes on. - handle: only the handle (the line and the knob) takes a press, so the pictures can hold links, a video with controls, or text to select. - hover: as drag, and a mouse over the frame moves the divider with no press.
mode"side-by-side""single""split""split"How the two versions show (the "Before and After" upgrade of the AI category). - split (default): one frame cut by a divider (the handle). - single: one version at a time, in one frame. value 100 shows the before and 0 the after; a change wipes across on the panel clock. A press and hold on the frame shows the other version until the release (the "hold to compare" of image editors). The handle does not show: put a switch (Tabs "Before" and "After") outside the frame as the keyboard path. - side-by-side: two frames next to each other (one above the other when vertical), 8px apart, each at ratio. No divider, no pointer, no keys; the value does nothing.
rationumber—The ratio of one picture (width over height, 16 / 9). Split and single: the frame takes it (an aspect-* class in className also works and wins). Side by side: each frame takes it (default 16 / 9), because the root holds two frames and has no ratio of its own.
classNamestring—
styleCSSProperties—
From Base UISlider.RootBase UI docs
disabledbooleanfalseWhether the slider should ignore user interaction.
formatNumberFormatOptions—Options to format the value.
localeLocalesArgument—The locale used by Intl.NumberFormat when formatting the value. Defaults to the user's runtime locale.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

ComparisonBefore

<div>
PropTypeDefaultDescription
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

ComparisonAfter

<div>
PropTypeDefaultDescription
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

ComparisonHandle

<div>
PropTypeDefaultDescription
classNamestring—
childrenReactNode—The knob content. Default: ChevronsLeftRight, or ChevronsUpDown when vertical.
getAriaValueTextdefaultValueTextThe value text for screen readers, from the share of the before. Default "40% before, 60% after".
From Base UISlider.ThumbBase UI docs
disabledbooleanfalseWhether the thumb should ignore user interaction.
aria-valuetextstring—A string value forwarded to the aria-valuetext attribute of the input. Ignored when getAriaValueText is provided.
getAriaLabel((index: number) => string) | null—A function which returns a string value for the aria-label attribute of the input.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

ComparisonLabel

<span>
PropTypeDefaultDescription
placement"bottom""top""top"top (default) or bottom, for a horizontal Comparison. The before label takes the start corner, the after label the end corner. Vertical: the before label is at the top start and the after label at the bottom start, whatever this says.
...props<span> attributes—Every other attribute goes to the <span>, with a ref.

ComparisonCaption

<div>
PropTypeDefaultDescription
mode"side-by-side""single""split""split"The mode of the Comparison under it, so each name sits over its version: split (default) puts the first name at the start and the last at the end; side-by-side puts each over its frame (two columns, 8px apart); single keeps the names together at the start.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.
  • Use it when the change is in the same place of both pictures.
  • Put a ComparisonAfter, a ComparisonBefore, and a ComparisonHandle inside.
  • Use interaction="handle" when the pictures hold links or text to select.
  • For many pictures in a row, use a Carousel.
  • To show one picture large, use an Image.
Arrow keysMoves the divider one step.
HomeorEndMoves the divider to the start or the end.
Divider
panel · after a press on the frame the divider glides to the pointer
  1. AddedComparison.
Open the release