Indeterminate to Determinate Progress
A progress bar that starts as an unknown-length shimmer, then switches to a real percentage once the total is known.
AI prompt
Clean UI mockup showing three states of one progress bar stacked vertically in a light theme: the top bar with a short blue segment in the middle of a pale track and the label Preparing, the middle bar filled 62 percent in blue with the label 62 percent and 12 seconds left, the bottom bar full in green with a check mark and the label Done, flat modern style, rounded ends. Negative: gradients, 3D, clutter, text errors, device frames. Reduced motion: static design.About this pattern
Definition
When you do not know how long something takes, an indeterminate bar tells people it is working. As soon as the size is known, switching to a determinate bar with a real percentage gives them a sense of time left. The switch should be smooth, never jumping back and forth.
Purpose & UX principles
- Start indeterminate: a moving segment or stripe, with role progressbar and no aria-valuenow.
- When the total is known, set aria-valuenow and animate the fill from the current position.
- Never move the percentage backwards.
- End with a clear done state and a short confirmation.
Interaction states
- Start the demo; it prepares, then reports percentages, then finishes.
Motion specification
- The stripe moves continuously while indeterminate.
- Reduced motion: the indeterminate state is a static striped bar with the text Preparing.
Responsive behaviour
- Announce changes politely, not for every percent.
- Offer Cancel for long tasks.
Code
<div class="bx"><div class="pb" id="pb" role="progressbar" aria-label="Processing file" aria-valuemin="0" aria-valuemax="100"><i id="fl"></i></div><p class="out" id="out" role="status"></p><div class="two"><button class="mini" id="go" type="button">Start</button><button class="mini" id="cn" type="button" disabled>Cancel</button></div></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.pb{height:12px;border-radius:6px;background:#e6e6e2;overflow:hidden;position:relative}.pb i{position:absolute;left:0;top:0;bottom:0;width:0;background:#2f6bff;border-radius:6px;transition:width .25s}.pb.ind i{width:35%;animation:ind 1.2s ease-in-out infinite}.pb.done i{background:#1f9d55}@keyframes ind{from{left:-35%}to{left:100%}}.out{font-size:13px;min-height:20px;margin:6px 0 0}.two{display:grid;grid-template-columns:1fr 1fr;gap:12px}.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}@media (prefers-reduced-motion:reduce){.pb.ind i{animation:none;left:0;width:100%;background:repeating-linear-gradient(45deg,#9db8ff 0 8px,#2f6bff 8px 16px)}.pb i{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const pb=document.getElementById('pb'),fl=document.getElementById('fl'),out=document.getElementById('out'),go=document.getElementById('go'),cn=document.getElementById('cn');let tm=null,v=0,t0=0;
function reset(){clearInterval(tm);clearTimeout(tm);pb.classList.remove('ind','done');pb.removeAttribute('aria-valuenow');fl.style.width='0';out.textContent='Ready.';go.disabled=false;cn.disabled=true;go.textContent='Start';}
function start(){reset();go.disabled=true;cn.disabled=false;pb.classList.add('ind');out.textContent='Preparing\u2026';tm=setTimeout(()=>{pb.classList.remove('ind');v=0;pb.setAttribute('aria-valuenow',0);fl.style.width='0%';tm=setInterval(()=>{v=Math.min(100,v+3+Math.random()*4);v=Math.round(v);pb.setAttribute('aria-valuenow',v);fl.style.width=v+'%';out.textContent=v+'% \u2013 about '+Math.max(1,Math.ceil((100-v)/12))+' s left';if(v>=100){clearInterval(tm);pb.classList.add('done');out.textContent='\u2713 Done';go.disabled=false;go.textContent='Run again';cn.disabled=true;}},200);},1800);}
go.addEventListener('click',start);cn.addEventListener('click',()=>{reset();out.textContent='Cancelled.';});reset();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Indeterminate to Determinate Progress — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.pb{height:12px;border-radius:6px;background:#e6e6e2;overflow:hidden;position:relative}.pb i{position:absolute;left:0;top:0;bottom:0;width:0;background:#2f6bff;border-radius:6px;transition:width .25s}.pb.ind i{width:35%;animation:ind 1.2s ease-in-out infinite}.pb.done i{background:#1f9d55}@keyframes ind{from{left:-35%}to{left:100%}}.out{font-size:13px;min-height:20px;margin:6px 0 0}.two{display:grid;grid-template-columns:1fr 1fr;gap:12px}.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}@media (prefers-reduced-motion:reduce){.pb.ind i{animation:none;left:0;width:100%;background:repeating-linear-gradient(45deg,#9db8ff 0 8px,#2f6bff 8px 16px)}.pb i{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="pb" id="pb" role="progressbar" aria-label="Processing file" aria-valuemin="0" aria-valuemax="100"><i id="fl"></i></div><p class="out" id="out" role="status"></p><div class="two"><button class="mini" id="go" type="button">Start</button><button class="mini" id="cn" type="button" disabled>Cancel</button></div></div>
</div>
<script>
const pb=document.getElementById('pb'),fl=document.getElementById('fl'),out=document.getElementById('out'),go=document.getElementById('go'),cn=document.getElementById('cn');let tm=null,v=0,t0=0;
function reset(){clearInterval(tm);clearTimeout(tm);pb.classList.remove('ind','done');pb.removeAttribute('aria-valuenow');fl.style.width='0';out.textContent='Ready.';go.disabled=false;cn.disabled=true;go.textContent='Start';}
function start(){reset();go.disabled=true;cn.disabled=false;pb.classList.add('ind');out.textContent='Preparing\u2026';tm=setTimeout(()=>{pb.classList.remove('ind');v=0;pb.setAttribute('aria-valuenow',0);fl.style.width='0%';tm=setInterval(()=>{v=Math.min(100,v+3+Math.random()*4);v=Math.round(v);pb.setAttribute('aria-valuenow',v);fl.style.width=v+'%';out.textContent=v+'% \u2013 about '+Math.max(1,Math.ceil((100-v)/12))+' s left';if(v>=100){clearInterval(tm);pb.classList.add('done');out.textContent='\u2713 Done';go.disabled=false;go.textContent='Run again';cn.disabled=true;}},200);},1800);}
go.addEventListener('click',start);cn.addEventListener('click',()=>{reset();out.textContent='Cancelled.';});reset();
</script>
</body></html>