shadcn.io is not affiliated with official shadcn/ui
Full-Width Before After Slider Hero Block for React
A showcase hero with centred copy over a wide before and after panel in a hairline frame, with a draggable handle and a band of four results.
Installation
Overview
A showcase hero where the comparison is the proof, for React with Base UI. Between solid page rails, an announcement pill, a headline, one sentence and two calls to action sit centred: a ShineButton that sweeps a light across it on hover, and an outline Button, both links. Below them a wide panel in a hairline frame, with + marks on its corners, draws the same checkout page twice for a fictional page-speed tool: the slow one, grey and still waiting for its image, over the fast one. Drag the round handle, or use the arrow keys, to wipe from one to the other. A band of four results, in cells that share their lines, closes the block. The handle is our Slider, so pointer, touch and keyboard all work; the copy fades in on load and the panel just after, with CSS transitions that stay still under reduced motion. For performance tools, code optimizers, image and media processing, and redesign showcases where the change is dramatic enough to lead the page.
FAQ
How do I replace the drawn pages with real screenshots?
Each side of the panel is one layer that fills it: the after layer underneath, the before layer on top, clipped at the handle. Replace either layer's CheckoutPage with an img that fills it (size-full object-cover), and use two images of the same size and framing so they line up under the divider. The layers are hidden from screen readers, so describe the change in the panel's caption, and keep the Before and After labels, which sit above both layers.
How does the handle follow the pointer?
The handle is our Slider, spread over the whole panel, with its track hidden and its thumb drawn as the round handle. Press anywhere on the panel and the handle jumps there, then follows your drag. Its value is written to the panel as a CSS variable, --split, and from it a second one, --edge, places the divide under the handle's centre: the before layer's clip-path, the divider line and the grip icon all read it. Nothing is measured in JavaScript.
Can keyboard and screen reader users use the comparison?
Yes. The handle is a slider named Compare before and after: Tab reaches it, the arrow keys move it one step, Page Up and Page Down ten, Home and End to either side, and it reads its value as 60% before, 40% after. The drawn pages are decoration, hidden from assistive technology, and an invisible caption gives the score and the largest paint on each side. The headline is the block's one h1, and the results band is a description list.
Where do the numbers in the band come from?
From the same two reports that draw the pages. BEFORE and AFTER at the top of the file hold the largest paint in milliseconds, the JavaScript shipped in kilobytes and the score, and the band's first and third figures are computed from them (a 5x faster paint, 54% less JavaScript), so the band can't drift from the pages. Change a report and both follow.
How does the hero behave on a phone?
The panel is 18rem tall on a phone, 20rem from sm and 26rem from md, and the drawn page drops its image and navigation on a phone so it stays readable. A sideways drag moves the handle, while an upward or downward swipe still scrolls the page, so the panel never traps the visitor. The headline and both actions are on the first screen, and the results band sits two by two, then one row of four from md.
Related
- Pro
Split Layout Before After Slider Hero
Interactive demosA split hero for a site speed tool: a headline, a Shine Button and a second action beside a speed report that fills its cell edge to edge, before on one side of a handle and after on the other.
- Pro
Split Panel Comparison Hero
Features and tablesA split hero for a status-page product: the headline and two calls to action beside a comparison table against a self-hosted page, in a hairline frame.
- Pro
Concentric Rings Hero
BackdropsA compact, centred hero for a design tool on solid rails: concentric rings breathe behind a headline, a Shine Button and an outline button, over a ruled band of three stats.
- Pro
Split Layout Feature Comparison Table Hero
Features and tablesA reverse split hero between solid rails: a compact comparison table in a framed figure beside a headline, a Shine Button and three trust points, with your column tinted.
- Pro
Hero With Stats
Stats and live dataA split hero with a headline, a Shine Button and a second action beside a rail of four key figures on shared hairlines, each with its period and a small bar trend.
- Pro
Centered Audience Tabs Hero
Interactive demosA compact centred hero with a role switch in a band that swaps the headline, the subtitle and a band of three checklist cells for designers, engineers and product teams.