Skip to content
Browse documentation

A desktop-grade resizable dual panel. Zero-lag drag, rubber-band spring limits, and double-click preset snapping.

Used forCode and docs editorsMaster and detail layoutsConsoles and logsComparison screens

Install with the shadcn CLI

$ npx shadcn@latest add @hairline/split-pane

Older shadcn CLI, or a network that blocks ui.shadcn.com? Install by URL: shadcn add https://hairlineui.com/r/split-pane.json. More

Templates

Need the whole page?

65 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 8 are free.

Where it’s used

  • Code and docs editors

    An editor on one side and a live preview on the other.

  • Master and detail layouts

    A list on the left with the selected item on the right.

  • Consoles and logs

    Output beside the tool that produced it.

  • Comparison screens

    Two versions or two documents side by side.

What it handles for you

Two panels that share a screen need a divider that feels right: it follows the pointer, resists at the limits, and can be reset in a double-click.

Instead of wiring upa resizable panel librarydivider drag handlingmin and max limitssnap presetscollapse buttons
  1. Dragging with no lag

    The divider updates the panes directly, without React re-rendering them.

  2. Rubber-band limits

    Pulling past the minimum or maximum meets resistance, then springs back.

  3. Double-click to snap

    Double-clicking the divider eases between 50/50, 25/75 and 75/25.

  4. Collapse either pane

    Arrows on the divider fold a pane away so the other fills the frame.

  5. Horizontal or vertical

    Split side by side or top and bottom.

  6. Keyboard control

    The divider is a separator: arrow keys step by 1% (10% with Shift), Enter snaps to 50/50, and Home and End jump to the limits.

Overview

Divide views cleanly with a 1px hairline boundary. Dragging adjusts panel ratios with immediate DOM updates, pulling past boundaries encounters logarithmic resistance before springing back through a damped harmonic oscillator (WAAPI), and double-clicking snaps cleanly between 50%, 25%, and 75% presets.

States

resize
Divider movement updates pane flex-basis directly without React state re-renders.
rubber-band
Dragging beyond min/max bounds introduces logarithmic resistance; release triggers a WAAPI spring back.
snap
Double-clicking the divider smoothly animates between 50/50, 25/75, and 75/25 presets over 380ms.
collapse
Collapse arrows fold either pane to 0 width, docking the hairline divider flush against the frame.

Usage

usage.tsx
import { SplitPane } from "@/components/split-pane";<SplitPane  defaultSplit={50}  first={<div className="p-4">Left Editor</div>}  second={<div className="p-4">Right Preview</div>}  onSplitCommit={setSplit}/>

Works with

Side-by-side markdown and live preview

Build dual-surface workspaces with independent scroll containers and zero layout jitter. Ideal for code playgrounds, markdown editors, and comparison screens.

example.tsx
"use client";import { useState } from "react";import { SplitPane } from "@/components/split-pane";export function DualWorkspace() {  const [split, setSplit] = useState(50);  return (    <div className="h-[480px] w-full rounded-2xl border border-border">      <SplitPane        split={split}        first={<div className="h-full bg-surface p-4 font-mono text-xs"># Document Source</div>}        second={<div className="h-full bg-background p-4 text-sm">Rendered Output</div>}        onSplitCommit={setSplit}      />    </div>  );}

Props

first / second
React.ReactNode
Content rendered inside the left/top and right/bottom panes.
split / defaultSplit= 50
number
Controlled or initial percentage allocated to the first pane.
minSize / maxSize= 15 / 85
number
Boundary thresholds in percentage before rubber-band resistance begins.
orientation= "horizontal"
"horizontal" | "vertical"
Primary axis of separation.
collapsible= true
boolean
Enables pane collapse buttons on the divider.
disabled= false
boolean
Locks the divider in place and prevents resizing.
onSplitChange
(split: number) => void
Fired during pointer movement with raw split percentages.
onSplitCommit
(split: number) => void
Fired upon pointer release or keyboard snap with normalized value.

Accessibility and motion

  • The divider button acts as a semantic role="separator" with aria-valuenow.
  • Arrow keys step by 1% (10% with Shift); Enter snaps to 50/50; Home and End jump to minimum and maximum limits.
  • Past boundary limits, WAAPI springFrames computes 33 keyframe values for fluid physical return.
  • Reduced motion removes transitions and settles snapped positions immediately.

Requirements

React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

Source

'use client';/* ───────────────────────────────────────────────────────── * SPLIT PANE: desktop-grade resizable dual surface * *   divider    1px hairline border with a centered grab pill; *              hover expands the line to an active primary accent *   drag       zero-lag direct DOM updates; dragging beyond *              min/max limits introduces logarithmic rubber-band *              resistance *   spring     releasing past boundary limits triggers an *              analytical WAAPI damped harmonic spring back *              to the boundary threshold *   snapping   double-clicking the divider smoothly cycles *              between 50%, 25%, and 75% preset layouts *   collapse   built-in controls fold either pane to 0 width, *              docking the hairline divider flush to the edge *   touch      expanded touch targets enable fluid dragging on *              mobile devices * * Fully accessible separator semantics with keyboard step. * ───────────────────────────────────────────────────────── */import * as React from 'react';import { ChevronLeft, ChevronRight, GripVertical } from 'lucide-react';import { INTERACTION_FOCUS, useInteractionReducedMotion } from './ui-interaction-motion';import { useSplitPane } from './use-split-pane';export interface SplitPaneProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {  first: React.ReactNode;  second: React.ReactNode;  split?: number;  defaultSplit?: number;  minSize?: number;  maxSize?: number;  orientation?: 'horizontal' | 'vertical';  collapsible?: boolean;  disabled?: boolean;  onSplitChange?: (split: number) => void;  onSplitCommit?: (split: number) => void;}export function SplitPane({  first,  second,  split,  defaultSplit = 50,  minSize = 15,  maxSize = 85,  orientation = 'horizontal',  collapsible = true,  disabled = false,  onSplitChange,  onSplitCommit,  className = '',  ...props}: SplitPaneProps) {  const reduced = useInteractionReducedMotion();  const isHorizontal = orientation !== 'vertical';  const pane = useSplitPane({    orientation,    split,    defaultSplit,    minSize,    maxSize,    disabled,    reduced,    onChange: onSplitChange,    onCommit: onSplitCommit,  });  return (    <div      {...props}      ref={(el) => pane.attachContainer(el)}      className={`relative flex select-none overflow-hidden rounded-[14px] border border-border bg-background ${        isHorizontal ? 'flex-row' : 'flex-col'      } ${className}`}    >      {/* First Pane */}      <div        ref={(el) => pane.attachFirstPane(el)}        className={`relative min-h-0 min-w-0 overflow-hidden ${          pane.collapsed === 'first' ? 'pointer-events-none' : ''        }`}        style={{ flexBasis: `${defaultSplit}%` }}      >        <div className="size-full overflow-auto">{first}</div>      </div>      {/* 1px Hairline Divider Container */}      <div        className={`relative z-10 shrink-0 touch-none ${          isHorizontal ? 'w-px cursor-col-resize' : 'h-px cursor-row-resize'        }`}      >        {/* Full Hairline Line */}        <div          className={`absolute inset-0 bg-border transition-colors ${            pane.dragging ? 'bg-primary' : 'hover:bg-primary/70'          }`}        />        {/* Dead-Centered Draggable Grab Handle Button */}        <button          ref={(el) => pane.attachDivider(el)}          {...pane.dividerProps}          type="button"          role="separator"          disabled={disabled}          aria-orientation={isHorizontal ? 'vertical' : 'horizontal'}          aria-valuenow={Math.round(split ?? defaultSplit)}          aria-valuemin={minSize}          aria-valuemax={maxSize}          aria-label="Resize split panes"          style={{            position: 'absolute',            left: '50%',            top: '50%',            transform: 'translate(-50%, -50%)',            touchAction: 'none',          }}          className={`group flex items-center justify-center rounded-full border border-border bg-background text-muted-foreground transition-colors hover:border-primary/50 hover:text-foreground active:scale-95 disabled:cursor-default disabled:opacity-40 before:absolute before:-inset-3 before:content-[''] ${            isHorizontal ? 'h-8 w-4.5 cursor-col-resize' : 'h-4.5 w-8 cursor-row-resize'          } ${INTERACTION_FOCUS}`}        >          <GripVertical className="size-3.5 opacity-60 transition-opacity group-hover:opacity-100" />        </button>        {/* Optional Collapsible Controls */}        {collapsible && !pane.dragging && (          <div            style={{              position: 'absolute',              left: isHorizontal ? '50%' : '12px',              top: isHorizontal ? '12px' : '50%',              transform: isHorizontal ? 'translate(-50%, 0)' : 'translate(0, -50%)',            }}            className={`z-20 flex items-center gap-0.5 ${              isHorizontal ? 'flex-col' : 'flex-row'            }`}          >            {pane.collapsed === 'first' ? (              <button                type="button"                onClick={pane.expand}                title="Restore pane"                className="cursor-pointer rounded-full border border-border bg-surface p-0.5 text-muted-foreground transition-colors hover:text-foreground"              >                <ChevronRight className="size-3" />              </button>            ) : pane.collapsed === 'second' ? (              <button                type="button"                onClick={pane.expand}                title="Restore pane"                className="cursor-pointer rounded-full border border-border bg-surface p-0.5 text-muted-foreground transition-colors hover:text-foreground"              >                <ChevronLeft className="size-3" />              </button>            ) : (              <div className="flex gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 hover:opacity-100">                <button                  type="button"                  onClick={() => pane.collapse('first')}                  title="Collapse left"                  className="cursor-pointer rounded border border-border bg-surface p-0.5 text-muted-foreground hover:text-foreground"                >                  <ChevronLeft className="size-2.5" />                </button>                <button                  type="button"                  onClick={() => pane.collapse('second')}                  title="Collapse right"                  className="cursor-pointer rounded border border-border bg-surface p-0.5 text-muted-foreground hover:text-foreground"                >                  <ChevronRight className="size-2.5" />                </button>              </div>            )}          </div>        )}      </div>      {/* Second Pane */}      <div        className={`relative min-h-0 min-w-0 flex-1 overflow-hidden ${          pane.collapsed === 'second' ? 'pointer-events-none' : ''        }`}      >        <div className="size-full overflow-auto">{second}</div>      </div>    </div>  );}

Registry item: /r/split-pane.json