Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Split Layout Before After Slider Hero Block for React

A 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.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

A split-layout hero with an interactive before and after comparison, for React with Base UI. The section sits on the page's drafting lines: two rails at the edges of the page column that continue into the blocks above and below, a rule along its top edge that runs to the page's edges, and a plus mark on each crossing. A divider splits the column, with a plus mark where it meets the top rule. On the start side, an announcement pill, a two-line headline for Trimline, a site speed optimizer, a subtitle, a primary ShineButton and an outline Button as links, and a small line of terms. On the other, a speed report fills its cell from the divider to the end rail: a score ring and three metrics, laid out the same way before and after, with the slow numbers (32, 4.8 s, 920 ms, 3.1 MB) on one side of a handle and the fast ones (98, 0.9 s, 40 ms, 480 KB) on the other, so dragging swaps the numbers in place. A native range input laid invisibly over the report moves the handle, with a mouse, a finger or the arrow keys. The copy fades and rises in on load with CSS transitions that stay still under reduced motion. It's built from Guides, Announcement, Status, Badge, Shine Button and Button with Lucide icons and Tailwind CSS. For performance tools, workflow and optimization products, redesign and migration pages: anywhere the change is the selling point.

FAQ

How do I change what the before and after sides show?

Both sides are drawn by one component, ReportLayer, from two objects at the top of the file: BEFORE and AFTER, each with a label, a score (the ring's fill, in percent) and three metrics. Edit those, or replace either layer's contents with your own markup; keep both layers in the same layout so the handle swaps values in place. Update the figure's hidden caption too, since it's what a screen reader says about the two sides.

How does the handle reveal one side over the other?

Both layers sit in the same grid cell, so they always share one height. The input's value is written to the figure as a CSS variable, --split, and the before layer's clip-path: inset() cuts it off at that point, while a 1 px handle sits at inset-inline-start the same value. The figure is dir="ltr", so before is always on the left, like a ruler. The browser does the rest: nothing is measured in JavaScript, so it stays smooth while you drag.

How are the lines and plus marks drawn?

They are the Guides component, an aria-hidden layer that draws the lines of the box it sits in. The page column (max-w-6xl, the same in every block) has Guides bleed marks="top" rules="top": two side rails that run the section's full height, so they join the rails of the blocks above and below, and one rule along the top edge that runs to the page's edges, with a plus on each crossing. The block below draws the next rule, so a stack of blocks never doubles a line. Inside, the divider is the report cell's lg:border-s with Guides marks="start" rules="none" sides={false} for the plus where it meets the top rule. The report is flush with the divider and the end rail, so it needs no frame. Every line is solid and is the theme's border colour, so it follows any preset.

Can keyboard and screen reader users compare the two sides?

Yes. The control is a native input type="range" named Compare before and after: the arrow keys move it one step, Home and End take it to either side, and its value reads as, for example, 50% before, 50% after. The figure shows a focus ring when the input has keyboard focus. The report's layers are decoration, hidden from assistive technology, and an invisible caption gives the figures on each side instead. The headline is the block's one h1.

How does the layout adapt to phones?

Below the lg breakpoint the two columns stack, with the report under the copy behind a ruled line, 24rem tall, and the headline wraps, balanced. The three metrics keep three columns down to 320 px, the input works with touch (touch-action: pan-y, so the page still scrolls), and the Shine Button is on the first screen of a phone.

When should I use this split layout instead of the full-width slider hero?

Use this split layout when the copy needs room beside the comparison: a longer subtitle, a line of terms, two calls to action. Use the full-width before and after slider hero when the comparison is striking enough to carry the hero on its own, with a handle you drag across the whole panel.

  • Pro

    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.

  • Pro

    Split Panel Comparison Hero

    Features and tables

    A 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

    A 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

    A showcase hero with start-aligned copy, a band of three checklist cells and a browser window in a hairline frame showing a deployments list.

  • Pro

    Split Stat Overlay Hero

    Stats and live data

    A split hero for a live revenue dashboard: the headline, a checklist and a Shine Button beside a dashboard sketch in a hairline frame, with three stat cards (revenue, users, churn) floating over its edges.

  • Pro

    A 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.