Top Page Loading Bar
A thin top bar that trickles forward while a page loads, fills when ready, then fades out.
AI prompt
Clean UI mockup of a browser window loading a new page, a thin bright blue progress bar along the very top edge filled about 70 percent with a soft glowing head at its end, below it the old page content slightly faded and the page title still visible, a small spinner-free address bar, light theme, flat modern style. Variant: the same bar in red when the load fails. Negative: heavy shadows, clutter, text errors, device frames. Reduced motion: static design.About this pattern
Definition
A top loading bar tells people a link was accepted and the next page is coming, even when the real progress is unknown. It starts quickly, slows down as it nears about 80 percent and waits there until the page is ready, then fills and fades out. It never reaches 100 percent early.
Purpose & UX principles
- Start on click, not after the request starts, to feel instant.
- Trickle: add smaller and smaller random steps up to about 90 percent.
- On completion jump to 100 percent, then fade out and reset after the fade.
- Use role progressbar or an aria-live note and avoid duplicating long text.
Interaction states
- Choose a page and press Go; or fail the load to see the error state.
Motion specification
- The bar eases forward and fades at the end.
- Reduced motion: it fills in steps without easing.
Responsive behaviour
- Do not show the bar for very fast loads under about 150 ms; delay it slightly.
- Provide a visible alternative when motion is reduced, such as a static bar.
Code
<div class="bx"><div class="bw"><div class="tb" id="tb" role="progressbar" aria-label="Page loading" aria-hidden="true"><i id="fl"></i></div><div class="pg" id="pg"><b id="tt">Home</b><p id="tx">Welcome back. Choose a page from the links below.</p></div></div><div class="two"><button class="mini" data-pg="Pricing" type="button">Go to Pricing</button><button class="mini" data-pg="Missing" type="button">Go to broken link</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}
.bw{position:relative;border:1px solid var(--line);border-radius:12px;overflow:hidden;background:#fff}.tb{height:4px;background:transparent;opacity:0;transition:opacity .3s}.tb.on{opacity:1}.tb i{display:block;height:100%;width:0;background:#2f6bff;box-shadow:0 0 8px #2f6bff;transition:width .25s}.tb.err i{background:#d92d20;box-shadow:0 0 8px #d92d20}.pg{padding:14px 14px 22px;min-height:84px;transition:opacity .2s}.pg.ld{opacity:.55}.pg b{font-size:16px}.pg p{margin:4px 0 0;font-size:12.5px;color:var(--muted)}.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){.tb,.tb i,.pg{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const tb=document.getElementById('tb'),fl=document.getElementById('fl'),pg=document.getElementById('pg'),tt=document.getElementById('tt'),tx=document.getElementById('tx');let w=0,tm=null,busy=false;const C={Pricing:['Pricing','Simple plans for every team size.'],Missing:['404','This page could not be loaded.']};
function set(v){w=v;fl.style.width=v+'%';tb.setAttribute('aria-valuenow',Math.round(v));}
function go(name){if(busy)return;busy=true;clearInterval(tm);tb.classList.remove('err');tb.classList.add('on');pg.classList.add('ld');set(8);tm=setInterval(()=>{const rest=90-w;set(w+Math.max(.6,rest*(.08+Math.random()*.1)));},260);
setTimeout(()=>{clearInterval(tm);const bad=name==='Missing';if(bad)tb.classList.add('err');set(100);setTimeout(()=>{tb.classList.remove('on');pg.classList.remove('ld');tt.textContent=C[name][0];tx.textContent=C[name][1];setTimeout(()=>{set(0);busy=false;},320);},320);},2600);}
document.querySelectorAll('[data-pg]').forEach(b=>b.addEventListener('click',()=>go(b.dataset.pg)));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>Top Page Loading Bar — 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}
.bw{position:relative;border:1px solid var(--line);border-radius:12px;overflow:hidden;background:#fff}.tb{height:4px;background:transparent;opacity:0;transition:opacity .3s}.tb.on{opacity:1}.tb i{display:block;height:100%;width:0;background:#2f6bff;box-shadow:0 0 8px #2f6bff;transition:width .25s}.tb.err i{background:#d92d20;box-shadow:0 0 8px #d92d20}.pg{padding:14px 14px 22px;min-height:84px;transition:opacity .2s}.pg.ld{opacity:.55}.pg b{font-size:16px}.pg p{margin:4px 0 0;font-size:12.5px;color:var(--muted)}.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){.tb,.tb i,.pg{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="bw"><div class="tb" id="tb" role="progressbar" aria-label="Page loading" aria-hidden="true"><i id="fl"></i></div><div class="pg" id="pg"><b id="tt">Home</b><p id="tx">Welcome back. Choose a page from the links below.</p></div></div><div class="two"><button class="mini" data-pg="Pricing" type="button">Go to Pricing</button><button class="mini" data-pg="Missing" type="button">Go to broken link</button></div></div>
</div>
<script>
const tb=document.getElementById('tb'),fl=document.getElementById('fl'),pg=document.getElementById('pg'),tt=document.getElementById('tt'),tx=document.getElementById('tx');let w=0,tm=null,busy=false;const C={Pricing:['Pricing','Simple plans for every team size.'],Missing:['404','This page could not be loaded.']};
function set(v){w=v;fl.style.width=v+'%';tb.setAttribute('aria-valuenow',Math.round(v));}
function go(name){if(busy)return;busy=true;clearInterval(tm);tb.classList.remove('err');tb.classList.add('on');pg.classList.add('ld');set(8);tm=setInterval(()=>{const rest=90-w;set(w+Math.max(.6,rest*(.08+Math.random()*.1)));},260);
setTimeout(()=>{clearInterval(tm);const bad=name==='Missing';if(bad)tb.classList.add('err');set(100);setTimeout(()=>{tb.classList.remove('on');pg.classList.remove('ld');tt.textContent=C[name][0];tx.textContent=C[name][1];setTimeout(()=>{set(0);busy=false;},320);},320);},2600);}
document.querySelectorAll('[data-pg]').forEach(b=>b.addEventListener('click',()=>go(b.dataset.pg)));
</script>
</body></html>