Snippets Draggable

Bootstrap 5 Drag and Drop Copy Between Lists

Two side-by-side people lists where items can be dragged or copied from one to the other, with drop highlighting and keyboard-friendly buttons.

Bootstrap 5 No jQuery Jun 2020 2.2K views

<section class="wdw-stage">
  <div class="container" style="max-width: 960px">
    <div class="text-center mb-4">
      <span class="wdw-eyebrow mb-2">Drag and drop</span>
      <h2 class="wdw-heading h3 mb-1">Copy people between lists</h2>
      <p class="wdw-muted mb-0">Drag a person across, or use the Copy button. The original stays where it is.</p>
    </div>
    <div class="row g-3 g-lg-4">
      <div class="col-md-6">
        <div class="wdw-card p-3 h-100">
          <div class="d-flex justify-content-between align-items-center px-2 pt-1 pb-2"><h3 class="h6 fw-bold mb-0">Directory</h3><span class="badge text-bg-secondary rounded-pill cl-count" data-for="cl-a"></span></div>
          <ul class="list-unstyled mb-0 cl-list" id="cl-a" aria-label="Directory">
        <li class="cl-item d-flex align-items-center gap-3 p-2 pe-3 rounded-4" draggable="true" data-id="1" data-name="Sam Idod" data-role="Product designer" data-img="1">
          <svg class="cl-grip text-body-tertiary flex-none" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><circle cx="9" cy="6" r="1.6"/><circle cx="15" cy="6" r="1.6"/><circle cx="9" cy="12" r="1.6"/><circle cx="15" cy="12" r="1.6"/><circle cx="9" cy="18" r="1.6"/><circle cx="15" cy="18" r="1.6"/></svg>
          <img src="https://i.pravatar.cc/80?img=1" alt="" width="40" height="40" class="rounded-circle flex-none">
          <div class="flex-grow-1 min-w-0"><div class="fw-semibold text-truncate">Sam Idod</div><div class="small wdw-muted text-truncate">Product designer</div></div>
          <button type="button" class="btn btn-sm btn-outline-primary rounded-pill cl-copy" aria-label="Copy Sam Idod to the other list">Copy</button>
        </li>
        <li class="cl-item d-flex align-items-center gap-3 p-2 pe-3 rounded-4" draggable="true" data-id="2" data-name="Patricia Lind" data-role="Frontend engineer" data-img="5">
          <svg class="cl-grip text-body-tertiary flex-none" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><circle cx="9" cy="6" r="1.6"/><circle cx="15" cy="6" r="1.6"/><circle cx="9" cy="12" r="1.6"/><circle cx="15" cy="12" r="1.6"/><circle cx="9" cy="18" r="1.6"/><circle cx="15" cy="18" r="1.6"/></svg>
          <img src="https://i.pravatar.cc/80?img=5" alt="" width="40" height="40" class="rounded-circle flex-none">
          <div class="flex-grow-1 min-w-0"><div class="fw-semibold text-truncate">Patricia Lind</div><div class="small wdw-muted text-truncate">Frontend engineer</div></div>
          <button type="button" class="btn btn-sm btn-outline-primary rounded-pill cl-copy" aria-label="Copy Patricia Lind to the other list">Copy</button>
        </li>
        <li class="cl-item d-flex align-items-center gap-3 p-2 pe-3 rounded-4" draggable="true" data-id="3" data-name="Tidoh Mark" data-role="Copywriter" data-img="">
          <svg class="cl-grip text-body-tertiary flex-none" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><circle cx="9" cy="6" r="1.6"/><circle cx="15" cy="6" r="1.6"/><circle cx="9" cy="12" r="1.6"/><circle cx="15" cy="12" r="1.6"/><circle cx="9" cy="18" r="1.6"/><circle cx="15" cy="18" r="1.6"/></svg>
          <span class="wdw-icon rounded-circle flex-none cl-ini" style="width:40px;height:40px">T</span>
          <div class="flex-grow-1 min-w-0"><div class="fw-semibold text-truncate">Tidoh Mark</div><div class="small wdw-muted text-truncate">Copywriter</div></div>
          <button type="button" class="btn btn-sm btn-outline-primary rounded-pill cl-copy" aria-label="Copy Tidoh Mark to the other list">Copy</button>
        </li>
        <li class="cl-item d-flex align-items-center gap-3 p-2 pe-3 rounded-4" draggable="true" data-id="4" data-name="Telon Maskun" data-role="Backend engineer" data-img="8">
          <svg class="cl-grip text-body-tertiary flex-none" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><circle cx="9" cy="6" r="1.6"/><circle cx="15" cy="6" r="1.6"/><circle cx="9" cy="12" r="1.6"/><circle cx="15" cy="12" r="1.6"/><circle cx="9" cy="18" r="1.6"/><circle cx="15" cy="18" r="1.6"/></svg>
          <img src="https://i.pravatar.cc/80?img=8" alt="" width="40" height="40" class="rounded-circle flex-none">
          <div class="flex-grow-1 min-w-0"><div class="fw-semibold text-truncate">Telon Maskun</div><div class="small wdw-muted text-truncate">Backend engineer</div></div>
          <button type="button" class="btn btn-sm btn-outline-primary rounded-pill cl-copy" aria-label="Copy Telon Maskun to the other list">Copy</button>
        </li>
        <li class="cl-item d-flex align-items-center gap-3 p-2 pe-3 rounded-4" draggable="true" data-id="5" data-name="Clark Handscomb" data-role="QA analyst" data-img="11">
          <svg class="cl-grip text-body-tertiary flex-none" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><circle cx="9" cy="6" r="1.6"/><circle cx="15" cy="6" r="1.6"/><circle cx="9" cy="12" r="1.6"/><circle cx="15" cy="12" r="1.6"/><circle cx="9" cy="18" r="1.6"/><circle cx="15" cy="18" r="1.6"/></svg>
          <img src="https://i.pravatar.cc/80?img=11" alt="" width="40" height="40" class="rounded-circle flex-none">
          <div class="flex-grow-1 min-w-0"><div class="fw-semibold text-truncate">Clark Handscomb</div><div class="small wdw-muted text-truncate">QA analyst</div></div>
          <button type="button" class="btn btn-sm btn-outline-primary rounded-pill cl-copy" aria-label="Copy Clark Handscomb to the other list">Copy</button>
        </li>
        <li class="cl-item d-flex align-items-center gap-3 p-2 pe-3 rounded-4" draggable="true" data-id="6" data-name="Jordan Stephens" data-role="Project manager" data-img="32">
          <svg class="cl-grip text-body-tertiary flex-none" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><circle cx="9" cy="6" r="1.6"/><circle cx="15" cy="6" r="1.6"/><circle cx="9" cy="12" r="1.6"/><circle cx="15" cy="12" r="1.6"/><circle cx="9" cy="18" r="1.6"/><circle cx="15" cy="18" r="1.6"/></svg>
          <img src="https://i.pravatar.cc/80?img=32" alt="" width="40" height="40" class="rounded-circle flex-none">
          <div class="flex-grow-1 min-w-0"><div class="fw-semibold text-truncate">Jordan Stephens</div><div class="small wdw-muted text-truncate">Project manager</div></div>
          <button type="button" class="btn btn-sm btn-outline-primary rounded-pill cl-copy" aria-label="Copy Jordan Stephens to the other list">Copy</button>
        </li>
          </ul>
        </div>
      </div>
      <div class="col-md-6">
        <div class="wdw-card p-3 h-100">
          <div class="d-flex justify-content-between align-items-center px-2 pt-1 pb-2"><h3 class="h6 fw-bold mb-0">Project team</h3><span class="badge text-bg-primary rounded-pill cl-count" data-for="cl-b"></span></div>
          <ul class="list-unstyled mb-0 cl-list" id="cl-b" aria-label="Project team">
            <li class="cl-empty text-center wdw-muted small py-4">Drop people here</li>
          </ul>
        </div>
      </div>
    </div>
    <p class="visually-hidden" role="status" aria-live="polite" id="cl-live"></p>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.