Skip to content
Site volume
Colourway

Components

Before and after

Two images of the same frame split by a draggable ink divider, driven by a native range.

  • Experimental
  • Reading layer
  • Client leaf
  • Since 0.9.0
  • Press check
Import from@maxgrits/overprint-react/before-after
On this page

BeforeAfter compares two images of the same frame: a 3 px ink divider with a 44 px handle splits them, and "Before" and "After" print on flat white plates in the top corners. The control is a native range laid over the whole frame, so a drag anywhere, the arrow keys and Home and End all move it, and vertical scrolling still works on phones.

Example#

Look of this example
Fernlight's homepage before and after the booking flow rebuild.
Live render of examples/before-after/basic.tsx

Usage#

Use before and after for two images of the same frame where the difference is the story: a redesign, a speed fix, a cleaned-up layout. A divider splits the images; dragging anywhere, the arrow keys, Page Up and Down, Home and End all move it.

  • Inputs. before and after are image elements with their own alt text; label names the comparison ("Fernlight homepage, before and after").
  • The control is a native range over the frame, with a value text such as "40 % before", so keyboards and screen readers get the full control.
  • Phones keep vertical scrolling: only sideways drags move the divider.

Anatomy#

Fernlight's homepage before and after the booking flow rebuild.
The parts of examples/before-after/basic.tsx, numbered:
  1. Framedata-mk-part="frame"
  2. Beforedata-mk-part="before"
  3. Afterdata-mk-part="after"
  4. Dividerdata-mk-part="divider"
  5. Handledata-mk-part="handle"
  6. Captiondata-mk-part="caption"

Volume#

Reading layer: identical at every volume.

  • Quiet

    Fernlight's homepage before and after the booking flow rebuild.

    Docs, forms, legal and long reads. Flat inks, no art in motion.

  • Studio

    Fernlight's homepage before and after the booking flow rebuild.

    The site default. Art on its own plates, one display moment per view.

  • Press

    Fernlight's homepage before and after the booking flow rebuild.

    Hero moments, covers and campaigns. Halftone fields and the second ink.

  • Rave

    Fernlight's homepage before and after the booking flow rebuild.

    Launches, posters and the 404. Every ink, and the words still win.

Content#

  • beforeLabel and afterLabel stay "Before" and "After" unless dates say more: "March", "June".
  • The caption says what changed and by how much, with the number.

Do and don't#

Do

Fernlight's homepage before and after the booking flow rebuild.

The same frame, two states.

Don't

Before and after images with different crops, so the divider compares two different pages.

Mismatched frames.

The comparison only works when everything except the change lines up. Crop both images to the same frame first.

Accessibility#

  • The range is named by label and says "40 % before" as its value.
  • Both images keep their own alt text.
  • The frame shows the focus ring while the range has focus; the handle turns to the selected face.
KeysWhat happens
TabFocuses the divider (the frame shows the ring)
Arrow LeftorArrow RightMoves the divider by 1 %
Page UporPage DownMoves the divider by 10 %
HomeorEndShows only the after or only the before image

The colour pairs it prints, with their contrast on both papers:

TextSurfaceRoleBoneNight
--mk-ink--mk-paper-platebody 18.42:1 · Lc 105.1, passes 15.02:1 · Lc 95.4, passes
--mk-text-2--mk-surfaceuinot in this looknot in this look

Process at Studio, normal contrast. Every look: the press check.

Props#

PropTypeDefaultDescription
before requiredReactElement<unknown, string | React.JSXElementConstructor<any>>noneThe earlier image (an element with its own alt text).
after requiredReactElement<unknown, string | React.JSXElementConstructor<any>>noneThe later image.
label requiredstringnoneNames the range ("Fernlight homepage, before and after").
beforeLabelstringnone
afterLabelstringnone
captionReactNodenoneA visible caption under the frame.
defaultValuenumber50The share of the frame showing the before image, 0 to 100 (default 50).
valuenumbernone
onValueChange((value: number) => void)none
aspectRatiostring"16 / 10"Width / height of the frame (default "16 / 10").

Plus 277 React and DOM attributes passed through to the root element (className, ref, aria-*, event handlers and the rest). Generated from BeforeAfterProps in packages/overprint-react/src/reading/before-after/before-after.tsx.

Tokens#

System tokens (19)

Its own properties (3)

  • --mk-before-after
  • --mk-before-after-divider
  • --mk-before-after-ratio

Scanned from its CSS at build and checked against its registry entry; 6 read but not declared there.

Changelog#

Arrived in 0.9.0.

0.9.024 October 2026