---
title: "Image compare"
subtitle: "<ImageCompare> stacks two images and lets you drag the divider left and right to compare them."
---

The two images sit on top of each other: `before` is left of the divider, `after` is right of it. Drag the handle or click anywhere on the image to move the divider; on phones, drag sideways to compare and swipe up or down to scroll the page as usual.

```mdx
<ImageCompare
  before="/assets/media/compare-before.jpg"
  after="/assets/media/compare-after.jpg"
  beforeLabel="Low-res"
  afterLabel="High-res"
  alt="The same image in low and high resolution"
/>
```

<ImageCompare
  before="/assets/media/compare-before.jpg"
  after="/assets/media/compare-after.jpg"
  beforeLabel="Low-res"
  afterLabel="High-res"
  alt="The same image in low and high resolution"
/>

Both images should have the same aspect ratio; if they don't, `after` sets the size and `before` is cropped to fill it. The handle works with the keyboard: arrow keys move it 1%, with Shift 10%, and Home and End move it to either edge. When printed, the two images appear side by side.

<ParamField path="before" type="url" required>The image left of the divider (`left` also works).</ParamField>
<ParamField path="after" type="url" required>The image right of the divider (`right` also works).</ParamField>
<ParamField path="beforeLabel" type="string">Label in the top-left corner; fades out as the divider gets close.</ParamField>
<ParamField path="afterLabel" type="string">Label in the top-right corner; fades out as the divider gets close.</ParamField>
<ParamField path="alt" type="string">Describes what the images compare; screen readers read it with the labels.</ParamField>
<ParamField path="position" type="number" default="50">Where the divider starts, in percent from the left (0–100).</ParamField>
<ParamField path="width" type="string">Display width: a number in pixels or a CSS length. Defaults to the full content width.</ParamField>
