Compare
Two versions of one thing, one over the other, with a divider the reader drags.
Compare puts two versions of one thing on top of each other, with a divider
between them. Drag the divider, or focus it and use the arrow keys, to see
more of one side or the other.


Pictures
Give each side a picture, the same way Image takes
one: import the file from next to the page, or give a URL. An imported file
that doesn’t exist fails the build, so a broken comparison never ships. Both
pictures should be the same size, so their details line up.
Each picture needs its own alt text, saying what it shows. With two pictures, the reader can drag anywhere on them.
Live content
A side can be a snippet instead, holding anything you can render: a component before and after a change, say. With live content, only the divider drags, so the reader can still click what’s inside. The labels sit in the top corners, so leave some room above the content.
Since 0.4 Shows a message that leaves on its own.
Added in 0.4. Shows a message that leaves on its own.
Labels and the divider
The labels say “Before” and “After” unless beforeLabel and afterLabel say
otherwise. They also name the divider for screen readers, which hear it as a
slider with how much of the first side shows. position sets where the
divider starts, as a percentage from the left.
| Key | Moves the divider |
|---|---|
| Left / Right arrow | 2% that way |
| Shift + an arrow | 10% that way |
| Home / End | All the way to an end |
For agents
Agents read the page as written, so they see both sides of the tag with their labels.
Props
before required stringSnippet import old from './old.png'), or a snippet of live content.after required stringSnippet beforeAlt string default ''afterAlt string default ''beforeLabel string default 'Before'afterLabel string default 'After'position number default 50