Context Window Usage Meter
A stacked bar of how much context is used by instructions, history, files and reply room.
AI prompt
Clean UI mockup of a chat sidebar footer with a horizontal context usage bar split into four segments, a dark grey System part, a blue Conversation part, a purple Attachment part and a hatched Reserved for reply part, the label 6,420 of 8,000 tokens used, an amber warning line below reading Earlier messages may be forgotten with a small Summarise button, light theme, flat modern style. Negative: gradients, 3D, clutter, text errors. Reduced motion: static design.About this pattern
Definition
Every model can read only so much text at once. A context meter shows people how full the window is, so they understand why a very long chat starts to forget early messages. Splitting the bar into parts shows what takes the space and what can be trimmed.
Purpose & UX principles
- Show segments: instructions, conversation, attachments and the space reserved for the reply.
- Use calm colours until about 80 percent, then a warning with a suggested action such as summarise earlier messages or start a new chat.
- Display approximate numbers and say they are estimates.
- Always keep room for the answer; block a send that would leave none.
Interaction states
- A Messages slider and an Attach file switch change usage.
Motion specification
- The bar updates in 200ms.
- Reduced motion: no transition.
Responsive behaviour
- Give the bar a text equivalent, such as 74 percent used.
- Do not alarm users early; reserve strong colours for real limits.
Code
<div class="bx"><div class="mb" id="mb" role="img" aria-label="Context usage"><i class="s1"></i><i class="s2"></i><i class="s3"></i><i class="s4"></i></div><p class="lg" id="lg"></p><p class="wr" id="wr" role="status"></p><label class="rw">Messages in chat <b id="mv">12</b><input id="ms" type="range" min="0" max="48" value="12"></label><label class="sw"><input id="at" type="checkbox"> Attach a long document</label></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}
.mb{display:flex;height:16px;border-radius:8px;overflow:hidden;background:#ececea;border:1px solid var(--line)}.mb i{display:block;height:100%;transition:width .2s}.s1{background:#6b6b70}.s2{background:#2f6bff}.s3{background:#8a5cf5}.s4{background:repeating-linear-gradient(45deg,#d5d5d0 0 4px,#e8e8e4 4px 8px)}.lg{font-size:12px;margin:6px 0;color:var(--muted)}.lg b{color:var(--text)}.wr{font-size:12.5px;min-height:34px;margin:0 0 6px;font-weight:600}.wr.w{color:#b45f06}.wr.e{color:#c0261a}.wr.ok{color:#1a7f45}.sw{display:flex;gap:6px;align-items:center;font-size:12px;color:var(--muted)}@media (prefers-reduced-motion:reduce){.mb i{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const W=8000,SY=600,PM=170,AT=2400,RS=1200,ms=document.getElementById('ms'),at=document.getElementById('at'),mb=document.getElementById('mb'),wr=document.getElementById('wr');
function up(){const n=+ms.value,cv=n*PM,ab=at.checked?AT:0,used=SY+cv+ab,free=Math.max(0,W-used),res=Math.min(RS,free),pct=Math.round(used/W*100);const seg=[SY,cv,ab,res].map(v=>Math.max(0,v));
[...mb.children].forEach((e,i)=>e.style.width=Math.min(100,seg[i]/W*100)+'%');const over=used+RS>W;
document.getElementById('lg').innerHTML='<b>'+used.toLocaleString('en-US')+'</b> of '+W.toLocaleString('en-US')+' tokens used (estimate) \u00b7 reply room '+res.toLocaleString('en-US');mb.setAttribute('aria-label','Context usage '+pct+' percent');document.getElementById('mv').textContent=n;
if(used>=W){wr.className='wr e';wr.textContent='Full: the oldest messages are being dropped. Start a new chat or summarise.';}else if(over){wr.className='wr e';wr.textContent='Not enough room left for a full reply. Summarise earlier messages.';}else if(pct>=80){wr.className='wr w';wr.textContent='Getting full: earlier messages may be forgotten soon.';}else{wr.className='wr ok';wr.textContent='Plenty of room.';}}
ms.addEventListener('input',up);at.addEventListener('change',up);up();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>Context Window Usage Meter — 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}
.mb{display:flex;height:16px;border-radius:8px;overflow:hidden;background:#ececea;border:1px solid var(--line)}.mb i{display:block;height:100%;transition:width .2s}.s1{background:#6b6b70}.s2{background:#2f6bff}.s3{background:#8a5cf5}.s4{background:repeating-linear-gradient(45deg,#d5d5d0 0 4px,#e8e8e4 4px 8px)}.lg{font-size:12px;margin:6px 0;color:var(--muted)}.lg b{color:var(--text)}.wr{font-size:12.5px;min-height:34px;margin:0 0 6px;font-weight:600}.wr.w{color:#b45f06}.wr.e{color:#c0261a}.wr.ok{color:#1a7f45}.sw{display:flex;gap:6px;align-items:center;font-size:12px;color:var(--muted)}@media (prefers-reduced-motion:reduce){.mb 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="mb" id="mb" role="img" aria-label="Context usage"><i class="s1"></i><i class="s2"></i><i class="s3"></i><i class="s4"></i></div><p class="lg" id="lg"></p><p class="wr" id="wr" role="status"></p><label class="rw">Messages in chat <b id="mv">12</b><input id="ms" type="range" min="0" max="48" value="12"></label><label class="sw"><input id="at" type="checkbox"> Attach a long document</label></div>
</div>
<script>
const W=8000,SY=600,PM=170,AT=2400,RS=1200,ms=document.getElementById('ms'),at=document.getElementById('at'),mb=document.getElementById('mb'),wr=document.getElementById('wr');
function up(){const n=+ms.value,cv=n*PM,ab=at.checked?AT:0,used=SY+cv+ab,free=Math.max(0,W-used),res=Math.min(RS,free),pct=Math.round(used/W*100);const seg=[SY,cv,ab,res].map(v=>Math.max(0,v));
[...mb.children].forEach((e,i)=>e.style.width=Math.min(100,seg[i]/W*100)+'%');const over=used+RS>W;
document.getElementById('lg').innerHTML='<b>'+used.toLocaleString('en-US')+'</b> of '+W.toLocaleString('en-US')+' tokens used (estimate) \u00b7 reply room '+res.toLocaleString('en-US');mb.setAttribute('aria-label','Context usage '+pct+' percent');document.getElementById('mv').textContent=n;
if(used>=W){wr.className='wr e';wr.textContent='Full: the oldest messages are being dropped. Start a new chat or summarise.';}else if(over){wr.className='wr e';wr.textContent='Not enough room left for a full reply. Summarise earlier messages.';}else if(pct>=80){wr.className='wr w';wr.textContent='Getting full: earlier messages may be forgotten soon.';}else{wr.className='wr ok';wr.textContent='Plenty of room.';}}
ms.addEventListener('input',up);at.addEventListener('change',up);up();
</script>
</body></html>