StartFoundationsComponentsContent

Splitter

A splitter divides an area into panels that people resize by dragging the handle between them, or with the keyboard.

Stable Figma
OverviewUsageAPIAccessibility

Folders

Messages

<tk-splitter style="block-size: 160px">
  <tk-splitter-panel size="30" min="15" max="60"><p>Folders</p></tk-splitter-panel>
  <tk-splitter-handle label="Resize folders"></tk-splitter-handle>
  <tk-splitter-panel><p>Messages</p></tk-splitter-panel>
</tk-splitter>

Anatomy

Part What it is
tk-splitter the group; lays out its panels along one axis and keeps their sizes
tk-splitter-panel one panel; holds anything and clips what overflows
tk-splitter-handle the line between two panels, with a 12px drag area; one Tab stop

Panels and handles are direct children of the group, in order: panel, handle, panel, and so on. A handle resizes only the two panels next to it.

Orientation and nesting

orientation="horizontal" (default) puts panels side by side. orientation="vertical" stacks them. For a two-way layout, put a group inside a panel.

Files

Editor

Console

<tk-splitter style="block-size: 240px">
  <tk-splitter-panel size="25" min="15"><p>Files</p></tk-splitter-panel>
  <tk-splitter-handle label="Resize files"></tk-splitter-handle>
  <tk-splitter-panel><tk-splitter orientation="vertical" style="block-size: 100%">
    <tk-splitter-panel size="70"><p>Editor</p></tk-splitter-panel>
    <tk-splitter-handle label="Resize console"></tk-splitter-handle>
    <tk-splitter-panel min="10"><p>Console</p></tk-splitter-panel>
  </tk-splitter></tk-splitter-panel>
</tk-splitter>

Give the group its size, such as a block-size or a grid track; the panels divide it.

Sizes

Sizes are percentages of the group.

  • size: the panel's starting share. Panels without one share what's left equally. After that, the splitter keeps the sizes as people drag.
  • min and max: the share a panel can't go below or above. A drag stops where either neighbor hits its limit, and the limits also hold when the window resizes. min is 0 by default, so set a floor where content must stay usable.
  • Double-click a handle to reset its two panels to their starting split.

Saving a layout

tk-resize fires on the group after every change a person makes, with detail.sizes. Read the sizes from sizes and restore them with setSizes(), which keeps each panel within its limits and doesn't fire tk-resize.

const splitter = document.querySelector('tk-splitter');
splitter.addEventListener('tk-resize', debounce(() => {
  localStorage.setItem('layout', JSON.stringify(splitter.sizes));
}, 200));
const saved = localStorage.getItem('layout');
if (saved) splitter.setSizes(JSON.parse(saved));

States

Fixed sidebar

Content

<tk-splitter style="block-size: 120px">
  <tk-splitter-panel size="30"><p>Fixed sidebar</p></tk-splitter-panel>
  <tk-splitter-handle label="Resize sidebar" disabled></tk-splitter-handle>
  <tk-splitter-panel><p>Content</p></tk-splitter-panel>
</tk-splitter>

On hover and while dragging, a 2px accent bar appears on the line. Keyboard focus shows a ring around the handle's drag area.

  • disabled: locks the two panels. The handle becomes a plain line that can't be dragged or focused.