All effectsClick & switch

Bézier Curve Control Point

贝塞尔曲线控制点

Dragging one control point bends a quadratic curve and updates both guide lines in place.

Drag the point or focus it and use arrow keys

Where to use it

Build vector tools, chart editors, and easing inspectors with immediate feedback. Show the handles and guide lines alongside the curve when users need to understand which control changed its shape.

Practical example

In a motion settings panel, dragging a single Bézier handle bends the preview curve immediately and moves the guides with it. The designer can watch how the handle changes the curve near each endpoint.

AI prompt

Add a quadratic Bézier editor to [surface]. Convert pointer coordinates to viewBox space, update path and handle guides together, and provide arrow keys and a reset action for the control point.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Bézier Curve Control Point</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .ui { width: min(100%, 238px); display: grid; gap: 8px; position: relative; font-size: 12px; line-height: 1.35; }
    .ui .surface { min-width: 0; border: 1px solid #676591; border-radius: 10px; background: #282744; padding: 8px; }
    .ui .bar { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
    .ui .actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 5px; }
    .ui .muted { color: #cecae9; font-size: 11px; }
    .ui .center { text-align: center; }
    .ui .mono { font: 11px ui-monospace, monospace; font-variant-numeric: tabular-nums; }
    .ui p { margin: 0; }
    .ui .button { min-height: 30px; padding: 4px 7px; border-radius: 7px; border: 1px solid #79779f; background: #3d3a60; color: #f9f5ff; font-size: 11px; font-weight: 650; cursor: pointer; }
    .ui .button:hover { background: #4e4976; }
    .ui .primary { background: #c5eeec; border-color: #dafaee; color: #17213b; }
    .ui .primary:hover { background: #e3fff9; }
    .ui .button:disabled { opacity: .6; cursor: default; }
    .ui .field { min-width: 0; width: 100%; border: 1px solid #79779f; border-radius: 6px; background: #1b1a31; color: #faf5ff; padding: 5px 7px; font-size: 12px; }
    .ui .field::placeholder { color: #c2bcdd; }
    .ui input[type="range"] { accent-color: #b8ebe0; width: 100%; min-width: 0; margin: 0; }
    .ui button { font: inherit; }
    .ui [hidden] { display: none !important; }
    .ui progress { accent-color: #b8ebe0; }
    @media (prefers-reduced-motion: reduce) {
      .ui *, .ui *::after, .ui *::before { transition-duration: 0s !important; animation-duration: 0s !important; scroll-behavior: auto !important; }
    }
    .curve-stage{position:relative;height:100px;border-radius:8px;border:1px solid #716b9d;background:repeating-linear-gradient(90deg,#ac9aea20 0 1px,transparent 1px 22px),repeating-linear-gradient(0deg,#ac9aea20 0 1px,transparent 1px 20px),#24213e}.curve-stage svg{width:100%;height:100%;position:absolute;inset:0;fill:none}.curve-stage .guide{stroke:#9684c0;stroke-dasharray:4 3}.curve-stage .curve{stroke:#b9efe3;stroke-width:3}.curve-stage circle{fill:#dcc7ff}.point{position:absolute;left:50%;top:17%;translate:-50% -50%;width:22px;height:22px;border:4px solid #292543;border-radius:50%;background:#ffcd8c;box-shadow:0 0 0 1px #bfabda;cursor:move;touch-action:none}
  </style>
</head>
<body>
  <main class="demo">
    <div class="ui"><div class="curve-stage" aria-label="Curve editor"><svg viewBox="0 0 220 100" preserveAspectRatio="none" aria-hidden="true"><path class="guide" d="M12 82 L110 17 L208 82"/><path class="curve" d="M12 82 Q110 17 208 82"/><circle cx="12" cy="82" r="3"/><circle cx="208" cy="82" r="3"/></svg><button class="point" type="button" aria-label="Curve control point"></button></div><div class="bar"><span class="mono coordinates">110, 17</span><button class="button reset" type="button">Reset</button></div></div>
  </main>
  <script>
    function dragOn(surface, handlers) {
      let pointer = null;
      let origin = null;
      function finish(event, canceled) {
        if (event.pointerId !== pointer) return;
        const delta = { x: event.clientX - origin.x, y: event.clientY - origin.y };
        pointer = null;
        handlers.end(delta, canceled);
      }
      surface.addEventListener('pointerdown', (event) => {
        if (pointer !== null || event.button !== 0) return;
        pointer = event.pointerId;
        origin = { x: event.clientX, y: event.clientY };
        surface.setPointerCapture(pointer);
        handlers.start?.(event);
      });
      surface.addEventListener('pointermove', (event) => {
        if (event.pointerId === pointer) {
          handlers.move({ x: event.clientX - origin.x, y: event.clientY - origin.y }, event);
        }
      });
      surface.addEventListener('pointerup', (event) => finish(event, false));
      surface.addEventListener('pointercancel', (event) => finish(event, true));
      surface.addEventListener('lostpointercapture', (event) => finish(event, true));
    }
    const clamp = (value, low, high) => Math.min(high, Math.max(low, value));

    const stage = document.querySelector('.curve-stage');
    const point = stage.querySelector('.point');
    let x = 110, y = 17;
    function set(nx, ny) {
      x = clamp(Math.round(nx), 13, 207); y = clamp(Math.round(ny), 12, 87);
      point.style.left = x / 2.2 + '%'; point.style.top = y + '%';
      stage.querySelector('.guide').setAttribute('d', 'M12 82 L' + x + ' ' + y + ' L208 82');
      stage.querySelector('.curve').setAttribute('d', 'M12 82 Q' + x + ' ' + y + ' 208 82');
      document.querySelector('.coordinates').textContent = x + ', ' + y;
    }
    dragOn(point, { move(delta, event) { const box = stage.getBoundingClientRect(); set((event.clientX - box.left) * 220 / box.width, (event.clientY - box.top) * 100 / box.height); }, end() {} });
    const directions = { ArrowLeft: [-3, 0], ArrowRight: [3, 0], ArrowUp: [0, -3], ArrowDown: [0, 3] };
    point.addEventListener('keydown', (event) => { const direction = directions[event.key]; if (direction) { event.preventDefault(); set(x + direction[0], y + direction[1]); } });
    document.querySelector('.reset').addEventListener('click', () => { set(110, 17); point.focus(); });
  </script>
</body>
</html>

Original example by UI Skills

Further examples