Patch Bandit

The story / The lab

Cheese puff · 2026-11-22

CSS resize handle: the property and a custom one

A CSS resize handle is the little corner you drag to make a box bigger or smaller. CSS draws one with a single property. If you want your own look, or want the keyboard to work too, you can build one by hand. Both ways are below, live, with the code.

Open up a box. Literally, this time: drag the corner.

The raccoon, mask on, with a knowing smirk

Way 1: the resize property

Add resize: both and overflow: auto to a box, and the browser draws a corner handle for you. No script. Drag the corner of the box on the right.

The handle's look is the browser's, though you can restyle it with ::-webkit-resizer in Chromium and Safari. Touch support varies by device, and the plain property does not respond to the keyboard.

The resize property (HTML and CSS)
<style>
  .box {
    width: 16rem; height: 8rem; padding: 0.8rem; border: 3px solid #86e3be; border-radius: 10px;
    resize: both;          /* none | both | horizontal | vertical */
    overflow: auto;        /* required: resize does nothing on overflow: visible */
    min-width: 10rem; min-height: 6rem;
    max-width: 100%;
  }

  /* Style the little corner (Chromium and Safari only) */
  .box::-webkit-resizer {
    background: linear-gradient(135deg, transparent 50%, #ff7b67 50% 60%, transparent 60% 72%, #ff7b67 72% 82%, transparent 82%);
  }
</style>

<div class="box"><p>Drag my corner.</p></div>

Drag my corner. I use resize: both.

Way 2: a custom handle

Want it to look your way, and work with the arrow keys? Build the handle as a real button, drag it with pointer events, and tell screen readers what happened. Try it: drag the corner, or tab to the handle and press the arrow keys.

The big idea is setPointerCapture, which keeps the drag going even when your pointer slides off the handle. The arrow keys use the same size function as the drag, so both stay inside the same limits.

The buttons are there for anyone who cannot drag at all. No pointer needed.

Resize me. I use a custom handle.

The code for the custom handle

Handle markup (HTML)
<div class="panel" id="panel">
  <p>Resize me.</p>
  <button type="button" class="handle" id="handle"
    aria-label="Resize handle. Use the arrow keys to resize the panel."></button>
</div>
<p class="sr" role="status" id="live"></p>

Handle styles (CSS)
/* hides text from the eye, keeps it for screen readers */
.sr { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.panel {
  box-sizing: border-box;   /* so the script's sizes include the border and padding */
  position: relative; width: 16rem; height: 8rem; min-width: 8rem; min-height: 5rem; max-width: 100%;
  background: #eef7f2; color: #170c26; border: 3px solid #86e3be; border-radius: 10px; padding: 0.8rem;
}
.handle {
  position: absolute; inset-block-end: 0; inset-inline-end: 0;
  width: 2rem; height: 2rem; border: 0; cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, #ff7b67 50%);
  touch-action: none;                              /* let the pointer drag, not scroll */
  -webkit-user-select: none; user-select: none;    /* no text selection while dragging */
}

Handle behavior (JavaScript)
const panel = document.getElementById('panel');
const handle = document.getElementById('handle');
const live = document.getElementById('live');
const STEP = 16, MIN_W = 128, MIN_H = 80;

function setSize(w, h) {
  const maxW = panel.parentElement.clientWidth;
  panel.style.width = Math.min(maxW, Math.max(MIN_W, w)) + 'px';
  panel.style.height = Math.max(MIN_H, h) + 'px';
}

let start = null;
handle.addEventListener('pointerdown', (e) => {
  if (e.button !== 0) return;
  start = { x: e.clientX, y: e.clientY, w: panel.offsetWidth, h: panel.offsetHeight };
  handle.setPointerCapture(e.pointerId);   // keep dragging when the pointer leaves the handle
});
handle.addEventListener('pointermove', (e) => {
  if (!start || !handle.hasPointerCapture(e.pointerId)) return;
  setSize(start.w + e.clientX - start.x, start.h + e.clientY - start.y);
});
handle.addEventListener('lostpointercapture', () => { start = null; });

handle.addEventListener('keydown', (e) => {
  const d = { ArrowRight: [STEP, 0], ArrowLeft: [-STEP, 0], ArrowDown: [0, STEP], ArrowUp: [0, -STEP] }[e.key];
  if (!d) return;
  e.preventDefault();
  setSize(panel.offsetWidth + d[0], panel.offsetHeight + d[1]);
  live.textContent = 'Panel is now ' + panel.offsetWidth + ' by ' + panel.offsetHeight + ' pixels.';
});

Tested in Chromium only. Pointer events and setPointerCapture are long supported in current browsers. On a touch screen the handle has touch-action: none, so dragging it does not scroll the page.

The fine print, in plain words

Why this is free

We're raccoons who think simple things shouldn't cost a monthly fee. We take techniques apart, explain them in plain words, and give them away. The code on this page is MIT licensed: copy it, change it, and share it.

This is one of twelve experiments so far. Our first browser tool (Bandit Codes) is live now, and the rest sit as ideas in the stash.