@gfazioli/mantine-compare
Mantine Compare is a responsive side‑by‑side comparison container that lets you render two pieces of content (images or custom React nodes) with consistent styling, layout controls, and accessibility.
Installation
After installation import package styles at the root of your application:
You can import styles within a layer @layer mantine-compare by importing @gfazioli/mantine-compare/styles.layer.css file.
Usage
The Compare is interactive component that allows you to compare two content sections by dragging a slider. It is particularly useful for visualizing differences between two versions of data.
Before
After
With Image Content
You can use the Compare component to compare two images by passing Image components as the leftSection and rightSection props.
With Code Content
You can use the Compare component to compare two code snippets by passing code blocks as the leftSection and rightSection props.
Labels
Use leftLabel and rightLabel props to display overlay text labels on each section. Labels are styled with a semi-transparent dark background and positioned at the top corners.
Angle
Use angle to control the divider orientation.
angle={0}behaves like the previous vertical direction (left/right compare)angle={90}behaves like the previous horizontal direction (top/bottom compare)- Any value between
0and360creates an oblique (diagonal) divider
Diagonal angle
Set angle to any value between 0 and 360 to get an oblique divider.
Drag boundaries
Use minDragBound and maxDragBound props to limit the slider movement range. Both props accept percentage values (0-100):
minDragBound- controls how far left/top the slider can be dragged (default: 0)maxDragBound- controls how far right/bottom the slider can be dragged (default: 100)
These boundaries work with any angle setting, making it useful for preventing the slider from completely hiding either section.
Left Section
Right Section
Variants
The Compare component supports three interaction variants:
Drag variant (default)
The default variant="drag" allows users to click and drag the slider button to compare content.
Hover variant
Set variant="hover" to reveal content by moving the mouse over the component. The slider button is hidden in this variant.
Fixed variant
Set variant="fixed" to display a static comparison at a specific position. The slider button is hidden and users cannot interact with the slider. Use defaultPosition to control the split position.
Before
After
Disabled
Set disabled to prevent all interactions (drag, hover, keyboard). The component appears with reduced opacity.
Left
Right
Slider styling
Customize the slider divider appearance with sliderColor and sliderWidth props. Both are exposed as CSS variables for fine-grained control.
Handle only
Set handleOnly to restrict dragging to the handle button only. When enabled, clicking and dragging on the slider line does not move the position — only the circular handle button responds to drag.
Auto-play
Set autoPlay to continuously animate the slider back and forth. The animation pauses when the user hovers over the component. Control the speed with autoPlaySpeed (1-100 scale, higher = faster, default 50). Choose an easing curve with autoPlayEasing: linear (default), ease-in, ease-out, ease-in-out, or spring.
Controlled position
Use the position prop with onPositionChange for full control over the slider position. This allows you to sync the slider with external controls like buttons or a Mantine Slider.
Position: 50%
Keyboard navigation
The Compare slider supports keyboard navigation. Click on the slider to focus it, then use:
- Arrow Left/Down: Move slider by
keyboardStep(default 1%) - Arrow Right/Up: Move slider by
keyboardStep(default 1%) - Shift + Arrow: Move slider by
keyboardShiftStep(default 10%) - Home: Move to minimum position
- End: Move to maximum position
Keyboard navigation respects minDragBound and maxDragBound constraints and is disabled for fixed and disabled states.
Before
After
Styles API
Compare supports Styles API, you can add styles to any inner element of the component with classNames prop. Follow Styles API documentation to learn more.
Before
After
Component Styles API
Hover over selectors to highlight corresponding elements