Markdown:
Components

Splitter

A draggable separator that coordinates the size of two panes.

Navigation

Drag the divider to resize this pane.

Content

The first pane consumes var(--svs-splitter).

Usage

Use standalone. The consumer supplies layout CSS that matches orientation; Splitter ships no layout CSS and only emits the first-pane size, e.g. display:flex with flex-basis: var(--svs-splitter).

Svelte
<Splitter {left} {right} />

Anatomy

The class attribute values represent part names. Other attributes represent their corresponding props. The consumer supplies layout CSS that matches orientation; Splitter ships no layout CSS and only emits the first-pane size.

Svelte
<div class="whole" {...rest} style data-orientation data-dragging>
  <div class="left" id>{left}</div>
  <div class="main" role="separator" tabindex="0" aria-controls aria-orientation aria-valuenow aria-valuemin aria-valuemax aria-label>
    {children}
  </div>
  <div class="right">{right}</div>
</div>

orientation drives the drag axis and arrow-key model: horizontal uses clientX / Left / Right, vertical uses clientY / Up / Down. The root emits a renameable first-pane size custom property (--svs-splitter by default, or cssvar.position) and exposes data-orientation; data-dragging is present only during an active pointer drag. Arrow keys move by step, Home moves to min, End moves to max, and keyboard movement clamps without snap. Pointer drag clamps and snaps to the nearest snap target within 3 percentage points. aria-orientation is perpendicular to layout orientation because it describes the separator bar itself: a left|right split has a vertical separator.

Props

NameTypeDefaultDescription
left*Snippet-Left pane content; receives variant
right*Snippet-Right pane content; receives variant
childrenSnippet-Splitter handle content; receives value and variant
orientation<enum>"horizontal"Drag axis and keyboard arrow model
valuenumber50Bindable first-pane percentage
minnumber0Minimum first-pane percentage
maxnumber100Maximum first-pane percentage
stepnumber1Keyboard step
snapnumber[]-Pointer-drag snap targets
labelstring-Accessible label for the separator
cssvarRecord-Renames the emitted first-pane size custom property
attachAttachment-Svelte attachment on the root div
elementHTMLDivElement-Bindable root div element
stylingSVSClass-Styling override
variantSVSVariantNEUTRALVariant

* required. Other HTMLAttributes are passed to the root <div> via rest props; class is merged onto the root.

Consumer layout CSS is required. For a horizontal split, use display:flex on whole and consume --svs-splitter with flex-basis: var(--svs-splitter) on the first pane.

aria-orientation is perpendicular to orientation because it describes the separator bar itself.

Styling

To learn more, see Styling.

Variant Management

No automatic switching.

Default Class Name

svs-splitter

Behavior

orientation drives the drag axis and arrow-key model: horizontal uses clientX / Left / Right, vertical uses clientY / Up / Down. The root emits a renameable first-pane size custom property (--svs-splitter by default, or cssvar.position) and exposes data-orientation; data-dragging is present only during an active pointer drag. Arrow keys move by step, Home moves to min, End moves to max, and keyboard movement clamps without snap. Pointer drag clamps and snaps to the nearest snap target within 3 percentage points. aria-orientation is perpendicular to layout orientation because it describes the separator bar itself: a left|right split has a vertical separator.

Accessibility

Keyboard Interactions

KeyDescription
ArrowLeftWhen orientation is "horizontal", decreases the first pane size by step
ArrowRightWhen orientation is "horizontal", increases the first pane size by step
ArrowUpWhen orientation is "vertical", decreases the first pane size by step
ArrowDownWhen orientation is "vertical", increases the first pane size by step
HomeMoves the separator to min
EndMoves the separator to max

Keyboard movement clamps to min / max and does not apply snap targets.

ARIA Roles and Attributes

The component applies these automatically:

  • Separator (main): role="separator", tabindex="0", aria-controls (the first pane), aria-orientation, aria-valuenow, aria-valuemin, aria-valuemax, and aria-label from label.

Provide an accessible name for the separator yourself because there is no built-in visible label. Pass the label prop. The managed separator role and value attributes are component-owned and omitted from SplitterProps.

Exports

Types

TypeScript
type SplitterCssVar = "position";
interface SplitterProps extends Omit<HTMLAttributes<HTMLDivElement>, "children" | "role" | "style"> {
  left: Snippet<[string]>; // Snippet<[variant]>
  right: Snippet<[string]>; // Snippet<[variant]>
  children?: Snippet<[number, string]>; // Snippet<[value,variant]>
  orientation?: "horizontal" | "vertical"; // ("horizontal")
  value?: number; // bindable (50)
  min?: number; // (0)
  max?: number; // (100)
  step?: number; // (1)
  snap?: number[]; // pointer-drag snap targets, within 3 percentage points
  label?: string;
  cssvar?: Partial<Record<SplitterCssVar, string>>;
  attach?: Attachment<HTMLDivElement>;
  element?: HTMLDivElement; // bindable
  styling?: SVSClass;
  variant?: SVSVariant; // (VARIANT.NEUTRAL)
  // class & other HTMLAttributes are passed to the root <div> via ...rest (class is merged onto root)
  // role and style are component-owned
}
type SplitterReqdProps = "left" | "right";
type SplitterBindProps = "value" | "element";

Others

No additional exports are available.

Examples

The example code uses Tailwind CSS along with SVSClass.

Basic

Navigation

Drag the divider to resize this pane.

Content

The first pane consumes var(--svs-splitter).

With Interactive Variant

Preset for Demo
Enter variant as you like
Navigater

Drag the divider to resize this pane.

Inspector

Snap targets are set at 30, 50, and 70.

Preview

Arrow keys move the separator by step.