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.
<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>
/* Web Designer Wall library style — shared base for every Bootstrap 5 snippet.
Indigo accent, Plus Jakarta Sans, soft cards, pill buttons. Works in light and dark. */
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");
:root,
[data-bs-theme="light"] {
--wdw-font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
--bs-body-font-family: var(--wdw-font);
--bs-primary: #4f46e5;
--bs-primary-rgb: 79, 70, 229;
--bs-primary-text-emphasis: #3730a3;
--bs-primary-bg-subtle: #eef2ff;
--bs-primary-border-subtle: #c7d2fe;
--bs-link-color: #4f46e5;
--bs-link-color-rgb: 79, 70, 229;
--bs-link-hover-color: #4338ca;
--bs-link-hover-color-rgb: 67, 56, 202;
--bs-focus-ring-color: rgba(79, 70, 229, 0.25);
--bs-border-radius: 0.75rem;
--bs-border-radius-lg: 1rem;
--bs-border-radius-xl: 1.25rem;
--wdw-radius-card: 1.25rem;
--wdw-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 40px -16px rgba(16, 24, 40, 0.22);
--wdw-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px -4px rgba(16, 24, 40, 0.12);
--wdw-stage: #f5f6fb;
}
[data-bs-theme="dark"] {
--bs-primary: #818cf8;
--bs-primary-rgb: 129, 140, 248;
--bs-primary-text-emphasis: #c7d2fe;
--bs-primary-bg-subtle: rgba(129, 140, 248, 0.14);
--bs-primary-border-subtle: rgba(129, 140, 248, 0.35);
--bs-link-color: #a5b4fc;
--bs-link-color-rgb: 165, 180, 252;
--bs-link-hover-color: #c7d2fe;
--bs-link-hover-color-rgb: 199, 210, 254;
--bs-focus-ring-color: rgba(129, 140, 248, 0.35);
--wdw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -16px rgba(0, 0, 0, 0.7);
--wdw-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px -4px rgba(0, 0, 0, 0.5);
--wdw-stage: #0f1117;
}
body { font-family: var(--wdw-font); -webkit-font-smoothing: antialiased; }
/* Bootstrap compiles its blue into these components; point them at the accent. */
.btn-primary {
--bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
--bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
--bs-btn-disabled-bg: var(--bs-primary); --bs-btn-disabled-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0f1117; --bs-btn-hover-bg: #a5b4fc; --bs-btn-hover-border-color: #a5b4fc; --bs-btn-hover-color: #0f1117; --bs-btn-active-color: #0f1117; }
.btn-outline-primary {
--bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary);
--bs-btn-active-bg: var(--bs-primary); --bs-btn-active-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn { --bs-btn-font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.btn-sm { min-height: 36px; }
.form-control, .form-select { min-height: 44px; border-radius: .75rem; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--bs-primary-rgb), .6); box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--bs-primary); }
.nav { --bs-nav-link-color: var(--bs-secondary-color); --bs-nav-link-hover-color: var(--bs-emphasis-color); }
.pagination { --bs-pagination-active-bg: var(--bs-primary); --bs-pagination-active-border-color: var(--bs-primary); --bs-pagination-color: var(--bs-body-color); --bs-pagination-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--bs-primary); }
.list-group { --bs-list-group-active-bg: var(--bs-primary); --bs-list-group-active-border-color: var(--bs-primary); }
.dropdown-menu { --bs-dropdown-link-active-bg: var(--bs-primary); border-radius: .875rem; box-shadow: var(--wdw-shadow-sm); }
.accordion { --bs-accordion-active-bg: var(--bs-primary-bg-subtle); --bs-accordion-active-color: var(--bs-primary-text-emphasis); --bs-accordion-btn-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.badge { font-weight: 600; }
/* Library building blocks — use these instead of re-inventing them per snippet. */
.wdw-stage { min-height: 100vh; display: flex; align-items: center; background: var(--wdw-stage); padding-block: 3rem; }
.wdw-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: var(--wdw-radius-card); box-shadow: var(--wdw-shadow); }
.wdw-card-sm { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 1rem; box-shadow: var(--wdw-shadow-sm); }
.wdw-aurora { position: relative; color: #fff; background: radial-gradient(60% 55% at 100% 0, #818cf8 0, transparent 70%), radial-gradient(65% 60% at 0 100%, #ec4899 0, transparent 65%), #1e1b4b; }
.wdw-eyebrow { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--bs-primary); }
.wdw-heading { font-weight: 800; letter-spacing: -.02em; color: var(--bs-emphasis-color); }
.wdw-muted { color: var(--bs-secondary-color); }
.wdw-icon { width: 2.75rem; height: 2.75rem; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: .875rem; background: var(--bs-primary-bg-subtle); color: var(--bs-primary); }
/* Component */
.cl-list { min-height: 120px; border-radius: 1rem; transition: background .15s, box-shadow .15s; }
.cl-list.cl-over { background: var(--bs-primary-bg-subtle); box-shadow: inset 0 0 0 2px var(--bs-primary); }
.cl-item { cursor: grab; transition: background .15s, opacity .15s; }
.cl-item:hover { background: var(--bs-tertiary-bg); }
.cl-item:active { cursor: grabbing; }
.cl-item.cl-drag { opacity: .4; }
.cl-item.cl-new { animation: cl-pop .4s ease; }
.cl-item .flex-none, .cl-list .flex-none { flex: none; }
.cl-item .min-w-0 { min-width: 0; }
.cl-ini { font-weight: 700; }
.cl-grip { cursor: grab; opacity: .8; }
@keyframes cl-pop { from { transform: scale(.96); background: var(--bs-primary-bg-subtle); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .cl-item.cl-new { animation: none; } }
.cl-item .btn-outline-secondary { --bs-btn-color: var(--bs-body-color); --bs-btn-border-color: var(--bs-border-color); }
(function () {
var dragged = null;
function lists() { return document.querySelectorAll('.cl-list'); }
function updateCounts() {
document.querySelectorAll('.cl-count').forEach(function (b) {
var list = document.getElementById(b.dataset.for);
var n = list ? list.querySelectorAll('.cl-item').length : 0;
b.textContent = n + (n === 1 ? ' person' : ' people');
var empty = list && list.querySelector('.cl-empty');
if (empty) empty.hidden = n > 0;
});
}
function announce(text) {
var live = document.getElementById('cl-live');
if (live) live.textContent = text;
}
function copyInto(item, target) {
if (item.parentElement === target) return;
if (target.querySelector('.cl-item[data-id="' + item.dataset.id + '"]')) {
announce(item.dataset.name + ' is already in that list');
return;
}
var clone = item.cloneNode(true);
clone.classList.remove('cl-drag');
clone.classList.add('cl-new');
var btn = clone.querySelector('.cl-copy');
var inTeam = target.id === 'cl-b';
btn.textContent = inTeam ? 'Remove' : 'Copy';
btn.classList.toggle('btn-outline-primary', !inTeam);
btn.classList.toggle('btn-outline-secondary', inTeam);
btn.setAttribute('aria-label', (inTeam ? 'Remove ' : 'Copy ') + item.dataset.name + (inTeam ? ' from this list' : ' to the other list'));
clone.dataset.copy = inTeam ? 'remove' : 'copy';
target.appendChild(clone);
announce('Copied ' + item.dataset.name);
updateCounts();
}
function initCloneLists() {
var all = lists();
if (!all.length) return;
var a = document.getElementById('cl-a');
var b = document.getElementById('cl-b');
all.forEach(function (list) {
list.addEventListener('dragstart', function (e) {
var item = e.target.closest('.cl-item');
if (!item) return;
dragged = item;
item.classList.add('cl-drag');
e.dataTransfer.effectAllowed = 'copy';
e.dataTransfer.setData('text/plain', item.dataset.id);
});
list.addEventListener('dragend', function () {
if (dragged) dragged.classList.remove('cl-drag');
dragged = null;
all.forEach(function (l) { l.classList.remove('cl-over'); });
});
list.addEventListener('dragover', function (e) {
if (!dragged || dragged.parentElement === list) return;
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
list.classList.add('cl-over');
});
list.addEventListener('dragleave', function (e) {
if (!list.contains(e.relatedTarget)) list.classList.remove('cl-over');
});
list.addEventListener('drop', function (e) {
e.preventDefault();
list.classList.remove('cl-over');
if (dragged) copyInto(dragged, list);
});
list.addEventListener('click', function (e) {
var btn = e.target.closest('.cl-copy');
if (!btn) return;
var item = btn.closest('.cl-item');
if (item.dataset.copy === 'remove') {
item.remove();
announce('Removed ' + item.dataset.name);
updateCounts();
return;
}
copyInto(item, list === a ? b : a);
});
});
// Pre-fill the second list so the demo starts populated.
[1, 4, 6].forEach(function (id) {
var src = a.querySelector('.cl-item[data-id="' + id + '"]');
if (src) copyInto(src, b);
});
b.querySelectorAll('.cl-item').forEach(function (i) { i.classList.remove('cl-new'); });
updateCounts();
}
initCloneLists();
})();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.