Attachment Chips with States
Files attached to a chat message shown as chips that go from uploading to ready, with remove buttons and clear errors.
AI prompt
Clean UI mockup of a chat composer with three attachment chips above the text field: a blue image chip photo.jpg 1.2 MB with a green check, a PDF chip report.pdf 3.4 MB with a thin progress bar at 60 percent, and a red chip video.mov Too large, max 25 MB with a retry text and an x, each chip with a small remove x button, the Send button greyed with a hint Waiting for uploads, light theme, flat modern style. Negative: heavy shadows, clutter, text errors. Reduced motion: static design.About this pattern
Definition
When people attach files to a message, each file needs a small visible card that shows its type, name, size and state. Uploading, ready and failed states must be different at a glance, and every chip needs a remove button. Errors should say what to do, such as a size limit and the maximum.
Purpose & UX principles
- One chip per file: type icon, name truncated in the middle, size, and a state indicator.
- Uploading: thin progress bar; ready: check; failed: red text with a reason and a retry or remove option.
- Remove button with an accessible name that includes the file name.
- Disable Send while any file is uploading, and say why.
Interaction states
- Add a photo, a PDF or a file that is too large; remove chips with the x button.
Motion specification
- Progress fills over about 1.5 seconds.
- Reduced motion: no progress animation; state changes at once.
Responsive behaviour
- Announce state changes politely, such as report.pdf ready.
- Validate type and size before uploading to save time.
Code
<div class="bx"><div class="chs" id="chs" aria-label="Attachments"></div><div class="cp"><div class="two"><button class="mini" data-f="photo" type="button">Add photo</button><button class="mini" data-f="pdf" type="button">Add PDF</button></div><div class="two"><button class="mini" data-f="video" type="button">Add large video</button><button class="mini send" id="sd" type="button">Send</button></div></div><p class="out" id="out" role="status"></p></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}
.chs{display:flex;flex-wrap:wrap;gap:6px;min-height:38px;margin-bottom:8px}.ch{position:relative;display:flex;align-items:center;gap:7px;padding:5px 26px 6px 6px;border:1px solid var(--line);border-radius:10px;background:#fff;font-size:11.5px;min-width:0;max-width:100%;overflow:hidden}.ch .ic{width:26px;height:26px;border-radius:6px;display:grid;place-items:center;font-size:9px;font-weight:800;color:#fff;flex:none}.ch .tx{display:grid;min-width:0}.ch .tx b{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ch .tx small{color:var(--muted);font-size:10.5px}.ch.err{border-color:#e7b3ae;background:#fff6f5}.ch.err small{color:#c0261a}.ch.ok small{color:#1a7f45}.ch .rm{position:absolute;right:3px;top:3px;width:18px;height:18px;border-radius:50%;font-size:12px;line-height:1;color:#666}.ch .rm:hover{background:#eee}.ch .pr{position:absolute;left:0;bottom:0;height:3px;background:#2f6bff;width:0;transition:width .12s}.cp{display:grid;gap:6px}.mini.send{background:#171717;color:#fff;border-color:#171717}.mini.send:disabled{background:#c9c9c4;border-color:#c9c9c4;color:#fff}.out{font-size:12px;color:var(--muted);min-height:16px;margin-top:6px}.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){.ch .pr{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const F={photo:['photo.jpg','1.2 MB','JPG','#2f6bff',false],pdf:['quarterly-report-final.pdf','3.4 MB','PDF','#d94f3d',false],video:['holiday-clip.mov','180 MB','MOV','#7c3aed',true]},chs=document.getElementById('chs'),out=document.getElementById('out'),sd=document.getElementById('sd'),calm=matchMedia('(prefers-reduced-motion:reduce)').matches;let items=[],id=0;
function draw(){chs.innerHTML=items.map(it=>'<div class="ch '+it.st+'" data-id="'+it.id+'"><span class="ic" style="background:'+it.c+'">'+it.t+'</span><span class="tx"><b title="'+it.n+'">'+it.n+'</b><small>'+(it.st==='up'?'Uploading\u2026 '+Math.round(it.p)+'%':it.st==='ok'?'\u2713 Ready \u00b7 '+it.s:'Too large \u2013 max 25 MB')+'</small></span><button class="rm" type="button" aria-label="Remove '+it.n+'">\u00d7</button>'+(it.st==='up'?'<i class="pr" style="width:'+it.p+'%"></i>':'')+'</div>').join('');
const busy=items.some(i=>i.st==='up'),bad=items.some(i=>i.st==='err');sd.disabled=busy;out.textContent=busy?'Send is off while files upload.':bad?'Remove the file that is too large, or choose a smaller one.':items.length?'Ready to send.':'No attachments.';}
function add(k){const f=F[k],it={id:++id,n:f[0],s:f[1],t:f[2],c:f[3],st:f[4]?'err':'up',p:0};items.push(it);draw();if(it.st==='up'){if(calm){it.p=100;it.st='ok';draw();return;}const iv=setInterval(()=>{if(!items.includes(it)){clearInterval(iv);return;}it.p=Math.min(100,it.p+9);if(it.p>=100){it.st='ok';clearInterval(iv);}draw();},130);}}
document.querySelectorAll('[data-f]').forEach(b=>b.addEventListener('click',()=>add(b.dataset.f)));chs.addEventListener('click',e=>{const b=e.target.closest('.rm');if(!b)return;const id=+b.closest('.ch').dataset.id;const it=items.find(i=>i.id===id);items=items.filter(i=>i.id!==id);draw();out.textContent='Removed '+it.n+'.';});
sd.addEventListener('click',()=>{items=[];draw();out.textContent='Sent.';});draw();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>Attachment Chips with States — 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}
.chs{display:flex;flex-wrap:wrap;gap:6px;min-height:38px;margin-bottom:8px}.ch{position:relative;display:flex;align-items:center;gap:7px;padding:5px 26px 6px 6px;border:1px solid var(--line);border-radius:10px;background:#fff;font-size:11.5px;min-width:0;max-width:100%;overflow:hidden}.ch .ic{width:26px;height:26px;border-radius:6px;display:grid;place-items:center;font-size:9px;font-weight:800;color:#fff;flex:none}.ch .tx{display:grid;min-width:0}.ch .tx b{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ch .tx small{color:var(--muted);font-size:10.5px}.ch.err{border-color:#e7b3ae;background:#fff6f5}.ch.err small{color:#c0261a}.ch.ok small{color:#1a7f45}.ch .rm{position:absolute;right:3px;top:3px;width:18px;height:18px;border-radius:50%;font-size:12px;line-height:1;color:#666}.ch .rm:hover{background:#eee}.ch .pr{position:absolute;left:0;bottom:0;height:3px;background:#2f6bff;width:0;transition:width .12s}.cp{display:grid;gap:6px}.mini.send{background:#171717;color:#fff;border-color:#171717}.mini.send:disabled{background:#c9c9c4;border-color:#c9c9c4;color:#fff}.out{font-size:12px;color:var(--muted);min-height:16px;margin-top:6px}.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){.ch .pr{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="chs" id="chs" aria-label="Attachments"></div><div class="cp"><div class="two"><button class="mini" data-f="photo" type="button">Add photo</button><button class="mini" data-f="pdf" type="button">Add PDF</button></div><div class="two"><button class="mini" data-f="video" type="button">Add large video</button><button class="mini send" id="sd" type="button">Send</button></div></div><p class="out" id="out" role="status"></p></div>
</div>
<script>
const F={photo:['photo.jpg','1.2 MB','JPG','#2f6bff',false],pdf:['quarterly-report-final.pdf','3.4 MB','PDF','#d94f3d',false],video:['holiday-clip.mov','180 MB','MOV','#7c3aed',true]},chs=document.getElementById('chs'),out=document.getElementById('out'),sd=document.getElementById('sd'),calm=matchMedia('(prefers-reduced-motion:reduce)').matches;let items=[],id=0;
function draw(){chs.innerHTML=items.map(it=>'<div class="ch '+it.st+'" data-id="'+it.id+'"><span class="ic" style="background:'+it.c+'">'+it.t+'</span><span class="tx"><b title="'+it.n+'">'+it.n+'</b><small>'+(it.st==='up'?'Uploading\u2026 '+Math.round(it.p)+'%':it.st==='ok'?'\u2713 Ready \u00b7 '+it.s:'Too large \u2013 max 25 MB')+'</small></span><button class="rm" type="button" aria-label="Remove '+it.n+'">\u00d7</button>'+(it.st==='up'?'<i class="pr" style="width:'+it.p+'%"></i>':'')+'</div>').join('');
const busy=items.some(i=>i.st==='up'),bad=items.some(i=>i.st==='err');sd.disabled=busy;out.textContent=busy?'Send is off while files upload.':bad?'Remove the file that is too large, or choose a smaller one.':items.length?'Ready to send.':'No attachments.';}
function add(k){const f=F[k],it={id:++id,n:f[0],s:f[1],t:f[2],c:f[3],st:f[4]?'err':'up',p:0};items.push(it);draw();if(it.st==='up'){if(calm){it.p=100;it.st='ok';draw();return;}const iv=setInterval(()=>{if(!items.includes(it)){clearInterval(iv);return;}it.p=Math.min(100,it.p+9);if(it.p>=100){it.st='ok';clearInterval(iv);}draw();},130);}}
document.querySelectorAll('[data-f]').forEach(b=>b.addEventListener('click',()=>add(b.dataset.f)));chs.addEventListener('click',e=>{const b=e.target.closest('.rm');if(!b)return;const id=+b.closest('.ch').dataset.id;const it=items.find(i=>i.id===id);items=items.filter(i=>i.id!==id);draw();out.textContent='Removed '+it.n+'.';});
sd.addEventListener('click',()=>{items=[];draw();out.textContent='Sent.';});draw();
</script>
</body></html>