Bootstrap 5 Draggable Sortable List with Product Cards
A reorderable product list: drag a card by its handle, or use the arrow keys, and the ranking updates instantly.
<section class="wdw-stage">
<div class="container" style="max-width:640px">
<div class="wdw-card p-3 p-md-4">
<div class="d-flex align-items-start justify-content-between gap-3 mb-3 px-1">
<div><span class="wdw-eyebrow">Merchandising</span><h2 class="wdw-heading h4 mb-1">Featured products</h2><p class="wdw-muted small mb-0" id="sortHint">Drag the handle to reorder, or focus it and press the arrow keys.</p></div>
<span class="badge text-bg-success rounded-pill align-self-center" id="sortStatus" role="status">Saved</span>
</div>
<ul class="list-unstyled d-grid gap-2 mb-0" id="sortable">
<li class="sortable-item d-flex align-items-center gap-2 gap-sm-3 p-2 pe-3 rounded-4 border bg-body">
<button type="button" class="drag-handle btn p-0 text-body-tertiary" aria-label="Reorder Studio Headphones" aria-describedby="sortHint"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01" stroke-width="4"/></svg></button>
<img src="https://images.unsplash.com/photo-1505740420928-5e560c06d30e?auto=format&fit=crop&w=200&h=200&q=70" width="64" height="64" class="rounded-3 object-fit-cover flex-shrink-0" alt="Studio Headphones" draggable="false">
<div class="flex-grow-1 wdw-min0"><h3 class="h6 mb-0 text-body-emphasis">Studio Headphones</h3><p class="small wdw-muted mb-0">Wireless over-ear, 40 h battery</p><span class="sortable-price fw-bold text-body-emphasis d-sm-none small">$149</span></div>
<span class="sortable-rank badge rounded-pill bg-body-secondary text-body-secondary">#1</span>
<span class="sortable-price fw-bold text-body-emphasis d-none d-sm-inline">$149</span>
<span class="sortable-move flex-column flex-shrink-0"><button type="button" class="btn btn-sm btn-outline-secondary rounded-circle p-0" data-move="-1" aria-label="Move Studio Headphones up"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 15 6-6 6 6"/></svg></button><button type="button" class="btn btn-sm btn-outline-secondary rounded-circle p-0" data-move="1" aria-label="Move Studio Headphones down"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></button></span>
</li>
<li class="sortable-item d-flex align-items-center gap-2 gap-sm-3 p-2 pe-3 rounded-4 border bg-body">
<button type="button" class="drag-handle btn p-0 text-body-tertiary" aria-label="Reorder Runner Sneakers" aria-describedby="sortHint"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01" stroke-width="4"/></svg></button>
<img src="https://images.unsplash.com/photo-1542291026-7eec264c27ff?auto=format&fit=crop&w=200&h=200&q=70" width="64" height="64" class="rounded-3 object-fit-cover flex-shrink-0" alt="Runner Sneakers" draggable="false">
<div class="flex-grow-1 wdw-min0"><h3 class="h6 mb-0 text-body-emphasis">Runner Sneakers</h3><p class="small wdw-muted mb-0">Lightweight mesh, recycled sole</p><span class="sortable-price fw-bold text-body-emphasis d-sm-none small">$89</span></div>
<span class="sortable-rank badge rounded-pill bg-body-secondary text-body-secondary">#2</span>
<span class="sortable-price fw-bold text-body-emphasis d-none d-sm-inline">$89</span>
<span class="sortable-move flex-column flex-shrink-0"><button type="button" class="btn btn-sm btn-outline-secondary rounded-circle p-0" data-move="-1" aria-label="Move Runner Sneakers up"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 15 6-6 6 6"/></svg></button><button type="button" class="btn btn-sm btn-outline-secondary rounded-circle p-0" data-move="1" aria-label="Move Runner Sneakers down"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></button></span>
</li>
<li class="sortable-item d-flex align-items-center gap-2 gap-sm-3 p-2 pe-3 rounded-4 border bg-body">
<button type="button" class="drag-handle btn p-0 text-body-tertiary" aria-label="Reorder Classic Watch" aria-describedby="sortHint"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01" stroke-width="4"/></svg></button>
<img src="https://images.unsplash.com/photo-1523275335684-37898b6baf30?auto=format&fit=crop&w=200&h=200&q=70" width="64" height="64" class="rounded-3 object-fit-cover flex-shrink-0" alt="Classic Watch" draggable="false">
<div class="flex-grow-1 wdw-min0"><h3 class="h6 mb-0 text-body-emphasis">Classic Watch</h3><p class="small wdw-muted mb-0">Brushed steel, sapphire glass</p><span class="sortable-price fw-bold text-body-emphasis d-sm-none small">$219</span></div>
<span class="sortable-rank badge rounded-pill bg-body-secondary text-body-secondary">#3</span>
<span class="sortable-price fw-bold text-body-emphasis d-none d-sm-inline">$219</span>
<span class="sortable-move flex-column flex-shrink-0"><button type="button" class="btn btn-sm btn-outline-secondary rounded-circle p-0" data-move="-1" aria-label="Move Classic Watch up"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 15 6-6 6 6"/></svg></button><button type="button" class="btn btn-sm btn-outline-secondary rounded-circle p-0" data-move="1" aria-label="Move Classic Watch down"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></button></span>
</li>
<li class="sortable-item d-flex align-items-center gap-2 gap-sm-3 p-2 pe-3 rounded-4 border bg-body">
<button type="button" class="drag-handle btn p-0 text-body-tertiary" aria-label="Reorder Aviator Sunglasses" aria-describedby="sortHint"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01" stroke-width="4"/></svg></button>
<img src="https://images.unsplash.com/photo-1572635196237-14b3f281503f?auto=format&fit=crop&w=200&h=200&q=70" width="64" height="64" class="rounded-3 object-fit-cover flex-shrink-0" alt="Aviator Sunglasses" draggable="false">
<div class="flex-grow-1 wdw-min0"><h3 class="h6 mb-0 text-body-emphasis">Aviator Sunglasses</h3><p class="small wdw-muted mb-0">Polarised lenses, titanium frame</p><span class="sortable-price fw-bold text-body-emphasis d-sm-none small">$129</span></div>
<span class="sortable-rank badge rounded-pill bg-body-secondary text-body-secondary">#4</span>
<span class="sortable-price fw-bold text-body-emphasis d-none d-sm-inline">$129</span>
<span class="sortable-move flex-column flex-shrink-0"><button type="button" class="btn btn-sm btn-outline-secondary rounded-circle p-0" data-move="-1" aria-label="Move Aviator Sunglasses up"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 15 6-6 6 6"/></svg></button><button type="button" class="btn btn-sm btn-outline-secondary rounded-circle p-0" data-move="1" aria-label="Move Aviator Sunglasses down"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></button></span>
</li>
<li class="sortable-item d-flex align-items-center gap-2 gap-sm-3 p-2 pe-3 rounded-4 border bg-body">
<button type="button" class="drag-handle btn p-0 text-body-tertiary" aria-label="Reorder Court Trainers" aria-describedby="sortHint"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01" stroke-width="4"/></svg></button>
<img src="https://images.unsplash.com/photo-1491553895911-0055eca6402d?auto=format&fit=crop&w=200&h=200&q=70" width="64" height="64" class="rounded-3 object-fit-cover flex-shrink-0" alt="Court Trainers" draggable="false">
<div class="flex-grow-1 wdw-min0"><h3 class="h6 mb-0 text-body-emphasis">Court Trainers</h3><p class="small wdw-muted mb-0">Leather upper, cushioned insole</p><span class="sortable-price fw-bold text-body-emphasis d-sm-none small">$99</span></div>
<span class="sortable-rank badge rounded-pill bg-body-secondary text-body-secondary">#5</span>
<span class="sortable-price fw-bold text-body-emphasis d-none d-sm-inline">$99</span>
<span class="sortable-move flex-column flex-shrink-0"><button type="button" class="btn btn-sm btn-outline-secondary rounded-circle p-0" data-move="-1" aria-label="Move Court Trainers up"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 15 6-6 6 6"/></svg></button><button type="button" class="btn btn-sm btn-outline-secondary rounded-circle p-0" data-move="1" aria-label="Move Court Trainers down"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></button></span>
</li>
<li class="sortable-item d-flex align-items-center gap-2 gap-sm-3 p-2 pe-3 rounded-4 border bg-body">
<button type="button" class="drag-handle btn p-0 text-body-tertiary" aria-label="Reorder Smart Speaker" aria-describedby="sortHint"><svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01" stroke-width="4"/></svg></button>
<img src="https://images.unsplash.com/photo-1558089687-f282ffcbc126?auto=format&fit=crop&w=200&h=200&q=70" width="64" height="64" class="rounded-3 object-fit-cover flex-shrink-0" alt="Smart Speaker" draggable="false">
<div class="flex-grow-1 wdw-min0"><h3 class="h6 mb-0 text-body-emphasis">Smart Speaker</h3><p class="small wdw-muted mb-0">Room-filling sound, voice control</p><span class="sortable-price fw-bold text-body-emphasis d-sm-none small">$79</span></div>
<span class="sortable-rank badge rounded-pill bg-body-secondary text-body-secondary">#6</span>
<span class="sortable-price fw-bold text-body-emphasis d-none d-sm-inline">$79</span>
<span class="sortable-move flex-column flex-shrink-0"><button type="button" class="btn btn-sm btn-outline-secondary rounded-circle p-0" data-move="-1" aria-label="Move Smart Speaker up"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 15 6-6 6 6"/></svg></button><button type="button" class="btn btn-sm btn-outline-secondary rounded-circle p-0" data-move="1" aria-label="Move Smart Speaker down"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></button></span>
</li>
</ul>
</div>
</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 */
.sortable-item { transition: box-shadow .2s, transform .2s, background-color .2s, border-color .2s; position: relative; }
.sortable-item:hover { box-shadow: var(--wdw-shadow-sm); border-color: var(--bs-primary-border-subtle) !important; }
.sortable-item:first-child { background: linear-gradient(90deg, var(--bs-primary-bg-subtle), var(--bs-body-bg) 60%) !important; border-color: var(--bs-primary-border-subtle) !important; }
.sortable-item:first-child .sortable-rank { background: var(--bs-primary) !important; color: #fff !important; }
.sortable-item img { flex: none; width: 64px; height: 64px; }
.drag-handle { width: 36px; height: 48px; flex: none; cursor: grab; display: grid; place-items: center; border: 0; touch-action: none; border-radius: .75rem; }
.drag-handle:hover, .drag-handle:focus-visible { color: var(--bs-primary) !important; background: var(--bs-primary-bg-subtle); }
.sortable-item.dragging { z-index: 2; transform: scale(1.03); box-shadow: 0 1.25rem 2.5rem rgba(0,0,0,.22); border-color: var(--bs-primary) !important; background: var(--bs-body-bg) !important; cursor: grabbing; }
.sortable-item.dragging::before { content: ""; position: absolute; left: 1rem; right: 1rem; top: -7px; height: 3px; border-radius: 3px; background: var(--bs-primary); }
.sortable-item.dragging .drag-handle { cursor: grabbing; color: var(--bs-primary) !important; }
.sortable-item.moved { animation: wdw-pop .35s ease; }
.sortable-move { display: none; gap: 2px; }
.sortable-move .btn { width: 30px; height: 30px; display: grid; place-items: center; }
@media (hover: none), (pointer: coarse) { .sortable-move { display: flex; } .sortable-move .btn { width: 36px; height: 36px; } }
@media (max-width: 575.98px) { .sortable-item .sortable-rank { display: none; } }
@keyframes wdw-pop { from { background: var(--bs-primary-bg-subtle); } }
@media (prefers-reduced-motion: reduce) { .sortable-item { transition: none; } .sortable-item.moved { animation: none; } .sortable-item.dragging { transform: none; } }
.wdw-min0 { min-width: 0; }
#sortable { grid-template-columns: minmax(0, 1fr); }
function initSortableList() {
const list = document.getElementById('sortable');
const status = document.getElementById('sortStatus');
if (!list) return;
let dragged = null;
const renumber = () => {
list.querySelectorAll('.sortable-item').forEach((li, i) => {
li.querySelector('.sortable-rank').textContent = '#' + (i + 1);
});
if (status) {
status.textContent = 'Order updated';
}
};
const flash = (li) => {
li.classList.remove('moved');
void li.offsetWidth;
li.classList.add('moved');
};
// Pointer-based drag: works for mouse, pen and touch
list.addEventListener('pointerdown', (e) => {
const handle = e.target.closest('.drag-handle');
if (!handle || (e.pointerType === 'mouse' && e.button !== 0)) return;
dragged = handle.closest('.sortable-item');
dragged.classList.add('dragging');
handle.setPointerCapture(e.pointerId);
});
list.addEventListener('pointermove', (e) => {
if (!dragged) return;
const others = [...list.querySelectorAll('.sortable-item')].filter((li) => li !== dragged);
const next = others.find((li) => {
const r = li.getBoundingClientRect();
return e.clientY < r.top + r.height / 2;
});
if (next) {
if (dragged.nextElementSibling !== next) list.insertBefore(dragged, next);
} else if (list.lastElementChild !== dragged) {
list.appendChild(dragged);
}
});
const end = () => {
if (!dragged) return;
dragged.classList.remove('dragging');
dragged = null;
renumber();
};
list.addEventListener('pointerup', end);
list.addEventListener('pointercancel', end);
const move = (li, dir) => {
const target = dir < 0 ? li.previousElementSibling : li.nextElementSibling;
if (!target) return false;
list.insertBefore(li, dir < 0 ? target : target.nextSibling);
flash(li);
renumber();
return true;
};
list.addEventListener('click', (e) => {
const btn = e.target.closest('[data-move]');
if (!btn) return;
move(btn.closest('.sortable-item'), Number(btn.dataset.move));
btn.focus();
});
list.addEventListener('keydown', (e) => {
const handle = e.target.closest('.drag-handle');
if (!handle || (e.key !== 'ArrowUp' && e.key !== 'ArrowDown')) return;
e.preventDefault();
move(handle.closest('.sortable-item'), e.key === 'ArrowUp' ? -1 : 1);
handle.focus();
});
}
initSortableList();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.