UI Components Medium
Upload Progress
Multi-file upload with individual progress bars, file type icons, cancel button, retry on error, and overall summary. No libraries.
Open in Lab
MCP
vanilla-js css
Targets: JS HTML
Code
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
background: #0d1117;
color: #e6edf3;
min-height: 100vh;
padding: 32px 16px;
display: flex;
justify-content: center;
align-items: flex-start;
}
.demo {
width: 100%;
max-width: 560px;
}
.up-panel {
background: #161b22;
border: 1px solid #21262d;
border-radius: 14px;
overflow: hidden;
}
/* Dropzone */
.up-dropzone {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8px;
padding: 36px 20px;
border-bottom: 1px solid #21262d;
text-align: center;
transition: background 0.2s;
}
.up-dropzone.dragover {
background: rgba(99, 102, 241, 0.06);
}
.up-dz-icon {
width: 48px;
height: 48px;
background: rgba(99, 102, 241, 0.12);
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
margin-bottom: 4px;
}
.up-dz-text {
font-size: 14px;
color: #8b949e;
}
.up-dz-link {
background: none;
border: none;
color: #6366f1;
font-size: 14px;
font-weight: 600;
cursor: pointer;
text-decoration: underline;
}
.up-dz-link:hover {
color: #818cf8;
}
.up-dz-sub {
font-size: 12px;
color: #4a555f;
}
/* Upload list */
.up-list {
display: flex;
flex-direction: column;
}
.up-item {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 18px;
border-bottom: 1px solid #21262d;
animation: up-in 0.25s ease;
}
@keyframes up-in {
from {
opacity: 0;
transform: translateY(-6px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.up-item:last-child {
border-bottom: none;
}
.up-item-icon {
width: 36px;
height: 36px;
border-radius: 8px;
background: rgba(255, 255, 255, 0.06);
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
flex-shrink: 0;
}
.up-item-body {
flex: 1;
min-width: 0;
}
.up-item-name {
font-size: 13px;
font-weight: 600;
color: #e6edf3;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-bottom: 6px;
}
.up-bar-wrap {
height: 5px;
background: #21262d;
border-radius: 3px;
overflow: hidden;
}
.up-bar-fill {
height: 100%;
border-radius: 3px;
transition: width 0.3s ease;
background: #6366f1;
}
.up-bar-fill--done {
background: #3fb950;
}
.up-bar-fill--error {
background: #f85149;
}
.up-item-meta {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 4px;
}
.up-item-status {
font-size: 11px;
color: #6c7086;
}
.up-item-status--done {
color: #3fb950;
}
.up-item-status--error {
color: #f85149;
}
.up-item-pct {
font-size: 11px;
color: #6c7086;
font-family: Menlo, monospace;
}
.up-item-remove {
background: none;
border: none;
color: #4a555f;
font-size: 14px;
cursor: pointer;
padding: 4px;
border-radius: 6px;
transition: all 0.15s;
flex-shrink: 0;
}
.up-item-remove:hover {
color: #f85149;
background: rgba(248, 81, 73, 0.08);
}
/* Footer */
.up-footer {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 18px;
border-top: 1px solid #21262d;
background: #1c2128;
gap: 12px;
flex-wrap: wrap;
}
.up-summary {
font-size: 12px;
color: #6c7086;
}
.up-footer-actions {
display: flex;
gap: 8px;
}
.up-btn {
padding: 7px 16px;
background: #6366f1;
color: #fff;
border: none;
border-radius: 8px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: opacity 0.15s;
}
.up-btn:hover {
opacity: 0.85;
}
.up-btn--ghost {
background: #21262d;
color: #8b949e;
border: 1px solid #30363d;
}
.up-btn--ghost:hover {
opacity: 1;
color: #e6edf3;
border-color: #8b949e;
}const DEMO_FILES = [
{ name: "report_q1_2026.pdf", size: "4.2 MB", icon: "📄" },
{ name: "hero_image.png", size: "2.8 MB", icon: "🖼" },
{ name: "data_export.xlsx", size: "1.1 MB", icon: "📊" },
{ name: "presentation.pptx", size: "8.6 MB", icon: "📋" },
{ name: "source_archive.zip", size: "22.4 MB", icon: "🗜" },
];
let items = [];
let demoIdx = 0;
function renderItems() {
const list = document.getElementById("upList");
const footer = document.getElementById("upFooter");
const summary = document.getElementById("upSummary");
list.innerHTML = "";
if (items.length === 0) {
footer.hidden = true;
return;
}
footer.hidden = false;
const done = items.filter((i) => i.status === "done").length;
const err = items.filter((i) => i.status === "error").length;
summary.textContent = `${done} of ${items.length} complete${err ? ` · ${err} failed` : ""}`;
items.forEach((item) => {
const div = document.createElement("div");
div.className = "up-item";
div.id = `up-item-${item.id}`;
const pctStr =
item.status === "done" ? "100%" : item.status === "error" ? "Failed" : `${item.pct}%`;
const fillCls =
item.status === "done"
? "up-bar-fill--done"
: item.status === "error"
? "up-bar-fill--error"
: "";
const statusCls =
item.status === "done"
? "up-item-status--done"
: item.status === "error"
? "up-item-status--error"
: "";
const statusText =
item.status === "done"
? "✓ Complete"
: item.status === "error"
? "✕ Failed"
: item.status === "pending"
? "Waiting…"
: "Uploading…";
div.innerHTML = `
<div class="up-item-icon">${item.icon}</div>
<div class="up-item-body">
<div class="up-item-name">${item.name}</div>
<div class="up-bar-wrap">
<div class="up-bar-fill ${fillCls}" style="width:${item.status === "done" ? 100 : item.pct}%"></div>
</div>
<div class="up-item-meta">
<span class="up-item-status ${statusCls}">${statusText}</span>
<span class="up-item-pct">${item.size} · ${pctStr}</span>
</div>
</div>
<button class="up-item-remove" data-id="${item.id}" title="Remove">✕</button>
`;
list.appendChild(div);
});
}
function startUpload(item) {
item.status = "uploading";
item.pct = 0;
renderItems();
const speed = 8 + Math.random() * 14;
const interval = setInterval(() => {
item.pct = Math.min(item.pct + speed * (0.8 + Math.random() * 0.4), 99);
renderItems();
if (item.pct >= 99) {
clearInterval(interval);
setTimeout(
() => {
item.status = Math.random() > 0.15 ? "done" : "error";
item.pct = 100;
renderItems();
},
300 + Math.random() * 400
);
}
}, 120);
}
document.getElementById("upSimBtn").addEventListener("click", () => {
const f = DEMO_FILES[demoIdx % DEMO_FILES.length];
demoIdx++;
const item = { id: Date.now(), ...f, pct: 0, status: "pending" };
items.push(item);
renderItems();
setTimeout(() => startUpload(item), 400);
});
document.getElementById("upUploadAllBtn").addEventListener("click", () => {
const pending = items.filter((i) => i.status === "pending" || i.status === "error");
pending.forEach((item, i) => {
setTimeout(() => startUpload(item), i * 300);
});
});
document.getElementById("upClearBtn").addEventListener("click", () => {
items = items.filter((i) => i.status === "uploading");
renderItems();
});
document.getElementById("upList").addEventListener("click", (e) => {
const btn = e.target.closest("[data-id]");
if (!btn) return;
const id = parseInt(btn.dataset.id);
items = items.filter((i) => i.id !== id);
renderItems();
});<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Upload Progress</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="demo">
<div class="up-panel">
<div class="up-dropzone" id="upDropzone">
<div class="up-dz-icon">⬆</div>
<p class="up-dz-text">Drop files here or <button class="up-dz-link" id="upSimBtn">simulate upload</button></p>
<p class="up-dz-sub">Supports PDF, DOC, XLS, images up to 50MB</p>
</div>
<div class="up-list" id="upList"></div>
<div class="up-footer" id="upFooter" hidden>
<div class="up-summary" id="upSummary"></div>
<div class="up-footer-actions">
<button class="up-btn up-btn--ghost" id="upClearBtn">Clear all</button>
<button class="up-btn" id="upUploadAllBtn">Upload all</button>
</div>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>Multi-file upload component with drag-and-drop zone, per-file animated progress bars, file type icons, cancel/retry buttons, error state, and an overall progress summary. Simulates uploads in the demo.