Split Pane Resizer
Two panes divided by a draggable separator that also works with arrow keys, with presets and a minimum width.
AI prompt
Clean UI design of a two-pane app window: a narrow file list on the left and a wide document preview on the right, separated by a thin vertical divider with a small grip of three dots in the middle, the left pane highlighted slightly, light neutral theme, rounded window corners, subtle shadow, flat modern interface, a small label showing 35 percent and 65 percent. Variants: divider at 50 percent and 70 percent, and a hover state with a darker divider line. Negative: heavy borders, gradients, text errors, cursor, clutter. Reduced motion: static design.About this pattern
Definition
A split pane lets the user decide how much room each side gets. The divider is a separator role element that can be dragged, moved with arrow keys and reset by double click or Enter, so mouse, touch and keyboard users all have control.
Purpose & UX principles
- Give the divider a wide invisible hit area (about 12px) around a thin visible line.
- Set a minimum size for each pane so neither can be dragged to nothing.
- Expose aria-valuenow, min and max so assistive technology can report the position.
Interaction states
- Three presets, drag, arrow keys, Home and End, and double click to reset.
Motion specification
- Dragging follows the pointer with no easing; presets animate over 200ms.
- Reduced motion: presets jump without animating.
Responsive behaviour
- On narrow screens stack the panes and hide the divider.
- Remember the position per user if the layout is important.
Code
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Presets"><button data-p="0" aria-pressed="true">30 / 70</button><button data-p="1" aria-pressed="false">50 / 50</button><button data-p="2" aria-pressed="false">70 / 30</button></div><div class="sp" id="sp"><div class="pa" id="pa"><b>Files</b><span id="lw">35%</span></div><div class="dv" id="dv" role="separator" tabindex="0" aria-orientation="vertical" aria-label="Resize panes" aria-valuemin="20" aria-valuemax="80" aria-valuenow="35"><i></i></div><div class="pb"><b>Preview</b><span id="rw">65%</span></div></div><p class="out">Drag the divider, or focus it and use the arrow keys. Double click resets.</p></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sp{display:flex;height:120px;border:1px solid var(--line);border-radius:12px;overflow:hidden;background:var(--surface);touch-action:none}
.pa,.pb{padding:10px 12px;font-size:12px;display:grid;align-content:start;gap:2px;overflow:hidden;min-width:0}.pa{width:var(--w,35%);background:#f6f6f3;transition:width .2s}.pb{flex:1}.pa b,.pb b{font-size:13px}.pa span,.pb span{color:var(--muted)}
.dv{width:12px;margin:0 -5px;position:relative;z-index:2;cursor:col-resize;display:grid;place-items:center;flex:none}.dv i{width:2px;height:100%;background:var(--line);border-radius:2px;transition:background .15s}.dv:hover i,.dv:focus-visible i,.dv.on i{background:var(--text)}
.dv:focus-visible{outline:none}.dv:focus-visible i{box-shadow:0 0 0 3px rgba(23,23,23,.2)}.sp.drag .pa{transition:none}
@media (prefers-reduced-motion:reduce){.pa{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const P=[30,50,70],sp=document.getElementById('sp'),pa=document.getElementById('pa'),dv=document.getElementById('dv'),bs=[...document.querySelectorAll('#pre button')];let w=35;
function set(v,anim){w=Math.max(20,Math.min(80,Math.round(v)));sp.classList.toggle('drag',!anim);pa.style.setProperty('--w',w+'%');dv.setAttribute('aria-valuenow',w);document.getElementById('lw').textContent=w+'%';document.getElementById('rw').textContent=(100-w)+'%';bs.forEach(b=>b.setAttribute('aria-pressed',String(P[+b.dataset.p]===w)));}
bs.forEach(b=>b.addEventListener('click',()=>set(P[+b.dataset.p],true)));
dv.addEventListener('pointerdown',e=>{dv.setPointerCapture(e.pointerId);dv.classList.add('on');});
dv.addEventListener('pointermove',e=>{if(!dv.hasPointerCapture(e.pointerId))return;const r=sp.getBoundingClientRect();set((e.clientX-r.left)/r.width*100,false);});
dv.addEventListener('pointerup',e=>{dv.classList.remove('on');});dv.addEventListener('dblclick',()=>set(50,true));
dv.addEventListener('keydown',e=>{const k={ArrowLeft:-5,ArrowRight:5}[e.key];if(k){e.preventDefault();set(w+k,false);}else if(e.key==='Home'){e.preventDefault();set(20,false);}else if(e.key==='End'){e.preventDefault();set(80,false);}else if(e.key==='Enter'){set(50,true);}});set(35,true);One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Split Pane Resizer — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sp{display:flex;height:120px;border:1px solid var(--line);border-radius:12px;overflow:hidden;background:var(--surface);touch-action:none}
.pa,.pb{padding:10px 12px;font-size:12px;display:grid;align-content:start;gap:2px;overflow:hidden;min-width:0}.pa{width:var(--w,35%);background:#f6f6f3;transition:width .2s}.pb{flex:1}.pa b,.pb b{font-size:13px}.pa span,.pb span{color:var(--muted)}
.dv{width:12px;margin:0 -5px;position:relative;z-index:2;cursor:col-resize;display:grid;place-items:center;flex:none}.dv i{width:2px;height:100%;background:var(--line);border-radius:2px;transition:background .15s}.dv:hover i,.dv:focus-visible i,.dv.on i{background:var(--text)}
.dv:focus-visible{outline:none}.dv:focus-visible i{box-shadow:0 0 0 3px rgba(23,23,23,.2)}.sp.drag .pa{transition:none}
@media (prefers-reduced-motion:reduce){.pa{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Presets"><button data-p="0" aria-pressed="true">30 / 70</button><button data-p="1" aria-pressed="false">50 / 50</button><button data-p="2" aria-pressed="false">70 / 30</button></div><div class="sp" id="sp"><div class="pa" id="pa"><b>Files</b><span id="lw">35%</span></div><div class="dv" id="dv" role="separator" tabindex="0" aria-orientation="vertical" aria-label="Resize panes" aria-valuemin="20" aria-valuemax="80" aria-valuenow="35"><i></i></div><div class="pb"><b>Preview</b><span id="rw">65%</span></div></div><p class="out">Drag the divider, or focus it and use the arrow keys. Double click resets.</p></div>
</div>
<script>
const P=[30,50,70],sp=document.getElementById('sp'),pa=document.getElementById('pa'),dv=document.getElementById('dv'),bs=[...document.querySelectorAll('#pre button')];let w=35;
function set(v,anim){w=Math.max(20,Math.min(80,Math.round(v)));sp.classList.toggle('drag',!anim);pa.style.setProperty('--w',w+'%');dv.setAttribute('aria-valuenow',w);document.getElementById('lw').textContent=w+'%';document.getElementById('rw').textContent=(100-w)+'%';bs.forEach(b=>b.setAttribute('aria-pressed',String(P[+b.dataset.p]===w)));}
bs.forEach(b=>b.addEventListener('click',()=>set(P[+b.dataset.p],true)));
dv.addEventListener('pointerdown',e=>{dv.setPointerCapture(e.pointerId);dv.classList.add('on');});
dv.addEventListener('pointermove',e=>{if(!dv.hasPointerCapture(e.pointerId))return;const r=sp.getBoundingClientRect();set((e.clientX-r.left)/r.width*100,false);});
dv.addEventListener('pointerup',e=>{dv.classList.remove('on');});dv.addEventListener('dblclick',()=>set(50,true));
dv.addEventListener('keydown',e=>{const k={ArrowLeft:-5,ArrowRight:5}[e.key];if(k){e.preventDefault();set(w+k,false);}else if(e.key==='Home'){e.preventDefault();set(20,false);}else if(e.key==='End'){e.preventDefault();set(80,false);}else if(e.key==='Enter'){set(50,true);}});set(35,true);
</script>
</body></html>