Progress Bar
进度条
A filled bar lengthens as a task advances, with an optional numeric value.
Where to use it
Show measured progress for an upload, download, or multi-step task. Advance the bar using bytes or completed steps so its length stays meaningful.
Practical example
When a photographer uploads a portfolio ZIP, the file row fills in proportion to the bytes received. The photographer can tell that 80 percent of the file is already through.
AI prompt
Add a Progress Bar to [target operation]. Bind its value to measured progress, clamp it to the valid range, and update a readable value label. Use a semantic progress element or equivalent progressbar semantics. Show an indeterminate state when progress is unknown and skip visual easing with reduced motion.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Progress Bar</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.progress-example { display: grid; justify-items: center; gap: 12px; width: min(100%, 270px); }
.progress-card {
width: 100%;
padding: 17px;
border: 1px solid #4e456d;
border-radius: 16px;
background: #252139;
color: #eee9fa;
}
.progress-heading {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
font-size: 13px;
font-weight: 600;
}
[data-progress-value] { color: #c6b5ff; font-variant-numeric: tabular-nums; }
progress {
display: block;
appearance: none;
width: 100%;
height: 9px;
overflow: hidden;
border: 0;
border-radius: 9px;
background: #45405a;
accent-color: #b9a6ff;
}
progress::-webkit-progress-bar { background: #45405a; }
progress::-webkit-progress-value {
border-radius: 9px;
background: linear-gradient(90deg, #9075f2, #d4b6ff);
}
progress::-moz-progress-bar {
border-radius: 9px;
background: linear-gradient(90deg, #9075f2, #d4b6ff);
}
</style>
</head>
<body>
<main class="demo">
<div class="progress-example">
<div class="progress-card">
<div class="progress-heading">
<label for="demo-progress">Export preview</label>
<span aria-hidden="true" data-progress-value>38%</span>
</div>
<progress id="demo-progress" max="100" value="38">38%</progress>
</div>
<button class="demo-button" type="button" data-start>Play demo</button>
</div>
</main>
<script>
const progress = document.querySelector('progress');
const valueLabel = document.querySelector('[data-progress-value]');
const start = document.querySelector('[data-start]');
function showProgress(value) {
const percentage = value + '%';
progress.value = value;
progress.textContent = percentage;
valueLabel.textContent = percentage;
}
let frame = 0;
start.addEventListener('click', () => {
cancelAnimationFrame(frame);
if (matchMedia('(prefers-reduced-motion: reduce)').matches) {
showProgress(100);
return;
}
showProgress(0);
const startedAt = performance.now();
function tick(now) {
const completed = Math.min(100, Math.floor((now - startedAt) / 13));
showProgress(completed);
if (completed < 100) frame = requestAnimationFrame(tick);
}
frame = requestAnimationFrame(tick);
});
</script>
</body>
</html>Original example by UI Skills