Add a resizable drag divider between panels with keyboard support. The lightweight attribute alternative to the full split-surface web component.
Overview
The data-splitter attribute adds a resizable drag divider between two panels. It supports horizontal and vertical orientations, keyboard navigation, and min/max constraints. This is the lightweight attribute alternative to the full <split-surface> web component.
For persistence, collapse, and triple-pane layouts, see the split-surface component page.
123456789
<section data-layout="sidebar" data-splitter> <nav aria-label="Sidebar"> <strong>Sidebar</strong> <p>Drag the divider or use arrow keys.</p> </nav> <main> <strong>Main Content</strong> </main></section>
Pairs naturally with the sidebar layout: the splitter switches it to no-wrap and drops the content column's minimum width so any content child (a main, a section data-layout="stack", a nested layout) can shrink beside the divider.
How It Works
Add data-splitter to a flex container with two child elements. The script needs at least two children and enhances only the first two; any further children are left alone and keep their normal flex sizing beside the second panel. The init script:
- Injects a
div.split-divider between the two children
- Sets
role="separator" on the divider with full ARIA attributes
- Listens for mouse drag, touch drag, and keyboard events on the divider
- Calculates the split position as a percentage and applies it to the first panel's flex-basis
- Reads
data-min and data-max from the first child for constraints
- Clamps the initial 50% position into the
data-min / data-max range
- Sets
data-splitter-init (styling hook); removing and re-inserting the container never adds a second divider
The container must be a flex container. The script sizes the first panel with flex-basis and never sets display itself, so a bare <section data-splitter>, or a grid layout such as data-layout="split" or data-layout="grid", renders unchanged. Use data-layout="sidebar" (or <layout-sidebar>) or data-layout="cluster" for side-by-side panels. For data-splitter="vertical" the splitter sets flex-direction: column itself, so any flex container works; data-layout="stack" is the usual choice.
Attributes
| Attribute |
Element |
Description |
data-splitter |
Container |
Enables the splitter. Empty string for side-by-side panels, "vertical" for stacked panels. |
data-label-resize |
Container |
Accessible name of the divider (default: "Resize panels"). Translate it for non-English pages. |
data-min |
First child |
Minimum size of the first panel as a percentage (default: 10). 0 and non-numeric values fall back to the default. |
data-max |
First child |
Maximum size of the first panel as a percentage (default: 90). 0 and non-numeric values fall back to the default. |
data-splitter-init |
Container |
Set automatically once enhanced. Do not set manually. |
Vertical Orientation
Set data-splitter="vertical" for a top/bottom split. The container needs a fixed height since vertical splits rely on the container's height to calculate proportions.
12345678
<section data-layout="stack" data-splitter="vertical" class="editor-panes"> <section>Top Panel</section> <section>Bottom Panel</section></section> <style> .editor-panes { block-size: 300px; }</style>
Min/Max Constraints
Add data-min and data-max to the first child element to constrain the drag range. Values are percentages. The divider stops at these boundaries during drag and keyboard navigation.
1234
<section data-layout="sidebar" data-splitter data-label-resize="Resize navigation"> <nav aria-label="Files" data-min="20" data-max="60">Sidebar</nav> <main>Content</main></section>
Injected Divider
The divider is a div.split-divider injected between the two child panels with the following accessibility attributes:
role="separator" and tabindex="0" for keyboard focus
aria-orientation naming the divider's own axis: vertical for side-by-side panels (a vertical bar), horizontal for stacked panels
aria-valuenow, aria-valuemin, aria-valuemax tracking the first panel's size
aria-controls pointing at the first panel (an id is generated if it has none)
aria-label from data-label-resize (default "Resize panels")
Keyboard Navigation
When the divider has focus, the following keyboard controls are available:
| Key |
Action |
| ArrowLeft / ArrowRight |
Move divider by 1% in the arrow's direction (side-by-side). Mirrored in RTL, where the first panel is on the right. |
| ArrowUp / ArrowDown |
Move divider by 1% (stacked) |
| Shift + Arrow |
Move divider by 10% |
| Home / End |
Move to minimum / maximum position |
Events
| Event |
Detail |
Description |
splitter:resize |
{ position } |
Fired on the container during drag and keyboard resize (not on init); it bubbles. position is the first panel's size as a percentage. The position is not persisted — use <split-surface> for that. |
12345
const panel = document.querySelector('[data-splitter]'); panel.addEventListener('splitter:resize', (e) => { console.log('Panel resized to:', e.detail.position + '%');});
Nested Splitters
Splitters can be nested for IDE-style layouts. Combine a horizontal sidebar split with a vertical editor/terminal split.
12345678910111213
<section data-layout="sidebar" data-splitter> <nav aria-label="File tree"> <strong>File Tree</strong> </nav> <section data-layout="stack" data-splitter="vertical" class="editor-panes"> <main> <strong>Editor</strong> </main> <section aria-label="Terminal"> <strong>Terminal</strong> </section> </section></section>
Styling
The divider is an injected div.split-divider; a ::after pseudo-element draws the grip. The rules live in src/web-components/split-surface/styles.css and are shared with <split-surface>. Layout fixes are gated on [data-splitter-init], so without JavaScript the panels stay in normal flow.
| Part | Default | Override with |
| Divider thickness | 5px (inline size for side-by-side panels, block size for vertical) | .split-divider { inline-size: … } |
| Divider colour | --color-border | the token, or background on .split-divider |
| Hover / dragging | --color-interactive | the token |
| Keyboard focus | 3px --color-focus outline (inset by 1px) | the token |
| Grip | 4×24px pill (24×4px when vertical), --color-text-muted at 50% opacity, 80% on hover | .split-divider::after |
| Cursor | col-resize / row-resize | — |
| Forced colours | Divider CanvasText, grip Canvas, hover/focus Highlight | — |
| Reduced motion | Colour transition switched off | — |
12345678
.editor-panes { --color-interactive: var(--color-primary);} .editor-panes > .split-divider { inline-size: 8px;}
Once enhanced, the container gets flex-wrap: nowrap (and flex-direction: column when vertical), and every panel loses its minimum content size so it can shrink beside the divider. The script also writes inline flex-grow, flex-shrink, flex-basis and overflow: auto on the first two panels, so your own CSS for those properties on the panels is overridden.
Dynamic Elements
Splitter containers added to the DOM after page load are automatically enhanced via a MutationObserver. No manual initialization is needed.
1234567
const container = document.createElement('section');container.dataset.layout = 'sidebar';container.dataset.splitter = '';container.innerHTML = '<nav>Side</nav><main>Content</main>';document.body.appendChild(container);
Accessibility
role="separator" identifies the divider as a resizable boundary to screen readers
aria-valuenow, aria-valuemin, and aria-valuemax convey position and range
aria-orientation is the divider's own axis (vertical for side-by-side panels)
aria-label (default "Resize panels", override with data-label-resize) provides the accessible name; aria-controls names the resized panel
- Pointer drag and arrow keys are direction-aware: in RTL the first panel is on the right and the controls mirror
- A cancelled drag (
pointercancel, lost capture) ends cleanly, restoring text selection
tabindex="0" makes the divider keyboard-focusable with a visible focus ring
- Full keyboard navigation: Arrow keys, Shift+Arrow, Home, and End
- The divider traps neither focus nor mouse — panel content remains fully interactive
- Without JavaScript, panels render in normal flow — progressive enhancement