All effectsClick & switch

Anchored Popover

锚点浮层

A compact panel appears next to its trigger and leaves the page usable.

Open the storage details

Where to use it

Show contextual details or preview secondary information without navigation. Choose this pattern for a small amount of content whose meaning depends on the control or value it sits beside.

Practical example

In a project planner, clicking the clock icon beside “14 hours” opens a compact breakdown of review and production time next to that estimate. The rest of the schedule stays usable.

Related design tip

Make optional help open by touch

AI prompt

Anchor a popover to [trigger]. Keep its placement inside the viewport, expose expanded state, dismiss on Escape or outside click, and avoid shifting the surrounding layout.

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>Anchored Popover</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;
    }

    .example { width: min(100%, 228px); position: relative; display: grid; gap: 10px; }
    .panel { background: #292240; border: 1px solid #675785; border-radius: 11px; padding: 10px; }
    .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
    .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
    .label { margin: 0; font-size: 13px; font-weight: 650; }
    .detail, .caption { margin: 0; color: #d7cbea; font-size: 11px; line-height: 1.35; }
    .caption { text-align: center; }
    .control { border: 1px solid #8874ae; background: #392e57; border-radius: 7px; padding: 5px 9px; min-height: 32px; color: #f6efff; cursor: pointer; font-size: 11px; font-weight: 650; }
    .control:hover { background: #514174; }
    .control.primary { color: #261b3f; background: #d1bfff; border-color: #e3d8ff; }
    .control.primary:hover { background: #e3d8ff; }
    .control:disabled { opacity: .55; cursor: default; }
    .field { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid #875fa8; border-radius: 6px; color: #f6efff; background: #1e1732; font-size: 12px; }
    .field::placeholder { color: #c2abd8; }
    [hidden] { display: none !important; }

    .popover-anchor { justify-self: center; position: relative; margin-bottom: 65px; }
    .popover { position: absolute; z-index: 1; left: 50%; top: calc(100% + 7px); width: 156px; transform: translateX(-50%); animation: pop .18s ease both; }
    .popover p + p { margin-top: 4px; }
    @keyframes pop { from { opacity: 0; translate: 0 -5px; } }

    @media (prefers-reduced-motion: reduce) {
      .example *, .example *::before, .example *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="example"><div class="popover-anchor"><button class="control primary" type="button" aria-expanded="false" aria-controls="help" data-help>Storage details</button><div class="panel popover" id="help" hidden><p class="label">48 / 64 GB</p><p class="detail">Photos use 36 GB.</p></div></div></div>
  </main>
  <script>
    const host = document.querySelector('.popover-anchor');
    const trigger = host.querySelector('[data-help]');
    const popover = host.querySelector('.popover');
    function setOpen(open) {
      trigger.setAttribute('aria-expanded', String(open));
      popover.hidden = !open;
    }
    trigger.addEventListener('click', () => setOpen(popover.hidden));
    document.addEventListener('click', (event) => {
      if (!host.contains(event.target)) setOpen(false);
    });
    document.addEventListener('keydown', (event) => {
      if (event.key === 'Escape' && !popover.hidden) {
        setOpen(false);
        trigger.focus();
      }
    });
  </script>
</body>
</html>

Original example by UI Skills