Snippets Card

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.

Bootstrap 5 No jQuery Jun 2020 2.2K views

<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>

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