All effectsClick & switch

Bottom Sheet Detents

底部面板停靠点

A draggable sheet settles at discrete heights with compact and expanded content states.

Drag the handle up or down, or tab to the height buttons

Where to use it

Show expandable filters or map details over the main view. Use the compact height for a summary and give the expanded height enough room for the decisions users make there.

Practical example

On a hiking map, tapping a trailhead opens a bottom sheet at its short height with the name and distance. Dragging the handle up makes it settle at the taller stop, revealing transport and trail notes.

AI prompt

Add a bottom sheet with detents to [view]. Define stable heights, drag only from the handle, commit the nearest stop on release, and make each height available with a button.

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>Bottom Sheet Detents</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; }
    }
    .sheet-viewport{height:146px;border-radius:10px;overflow:hidden;position:relative;background:#243650}.map{position:absolute;inset:0;background:repeating-linear-gradient(28deg,#49bdb629 0 2px,transparent 2px 20px),repeating-linear-gradient(-48deg,#8cafed40 0 1px,transparent 1px 22px),linear-gradient(130deg,#223752,#2f5461)}.sheet{position:absolute;bottom:0;width:100%;height:94px;display:grid;align-content:start;gap:5px;overflow:hidden;transition:height .22s ease-out}.sheet[data-drag]{transition:none}.handle{justify-self:center;width:62px;height:17px;border:0;border-radius:4px;background:linear-gradient(#a5a0c8,#a5a0c8) center/27px 4px no-repeat;cursor:ns-resize;touch-action:none}.sheet [aria-pressed=true]{background:#b8ebe0;color:#201e37}
  </style>
</head>
<body>
  <main class="demo">
    <div class="ui"><div class="sheet-viewport"><div class="map" aria-hidden="true"></div><div class="surface sheet"><button class="handle" type="button" aria-label="Change sheet height"></button><div class="bar"><strong>Studio filters</strong><span class="mono" role="status">1 / 3</span></div><div class="actions"><button class="button" data-stop="0" aria-pressed="true">Low</button><button class="button" data-stop="1" aria-pressed="false">Half</button><button class="button" data-stop="2" aria-pressed="false">Full</button></div><p class="muted">2 places near the river</p></div></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 sheet = document.querySelector('.sheet');
    const handle = sheet.querySelector('.handle');
    const heights = [94, 118, 144];
    let index = 0;
    let dragged = false;
    function setStop(stop) {
      index = stop; sheet.style.height = heights[index] + 'px';
      sheet.querySelector('.muted').hidden = index === 0;
      sheet.querySelector('[role=status]').textContent = (index + 1) + ' / 3';
      for (const option of sheet.querySelectorAll('[data-stop]')) option.setAttribute('aria-pressed', String(Number(option.dataset.stop) === index));
    }
    setStop(index);
    for (const option of sheet.querySelectorAll('[data-stop]')) option.addEventListener('click', () => setStop(Number(option.dataset.stop)));
    handle.addEventListener('click', () => { if (!dragged) setStop((index + 1) % heights.length); dragged = false; });
    dragOn(handle, {
      start() { dragged = false; sheet.setAttribute('data-drag', ''); },
      move(delta) { dragged ||= Math.abs(delta.y) > 4; sheet.style.height = clamp(heights[index] - delta.y, heights[0], heights[2]) + 'px'; },
      end(delta, canceled) { sheet.removeAttribute('data-drag'); const goal = heights[index] - delta.y; setStop(canceled ? index : heights.reduce((best, height, i) => Math.abs(height - goal) < Math.abs(heights[best] - goal) ? i : best, index)); },
    });
  </script>
</body>
</html>

Original example by UI Skills

Further examples