Response Version Switcher
An AI answer with a 1/3 switcher so people can regenerate and flip between versions without losing earlier ones.
AI prompt
Clean chat UI mockup of an AI assistant reply to the question Give me a tagline for a coffee shop, below the answer a small control bar with a left arrow, the text 2 / 3, a right arrow, a Regenerate button with a circular arrow icon and thumbs up and down icons, the answer text slightly different in three states, light theme, flat modern style, comfortable spacing. Negative: robots, heavy shadows, gradients, text errors, clutter. Reduced motion: static mockup.About this pattern
Definition
When an AI answer misses, people regenerate it. If each regeneration replaces the old one, the best version can be lost. A version switcher keeps every answer, shows which one is on screen, and lets people move back and forth and keep the one they like.
Purpose & UX principles
- Show the position as 2 of 3 with previous and next arrows.
- Keep earlier versions; regenerating adds a new one at the end.
- Announce the change to screen readers and keep keyboard access to the arrows.
- Let people copy or continue from whichever version is showing.
Interaction states
- Regenerate, previous and next buttons, and a version counter.
Motion specification
- A new version takes about 600ms to appear with a dots indicator.
- Reduced motion: the answer appears at once.
Responsive behaviour
- Cap the number of versions, such as five, and say so.
- Do not hide that a new version is being generated; show a loading state.
Code
<div class="bx"><div class="q">Give me a tagline for a coffee shop.</div><div class="a" id="an" aria-live="polite"></div><div class="bar"><button class="ic" id="pv" type="button" aria-label="Previous version">‹</button><span id="ct">1 / 1</span><button class="ic" id="nx" type="button" aria-label="Next version">›</button><button class="mini" id="rg" type="button">Regenerate</button></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}
.q{align-self:end;justify-self:end;background:#171717;color:#fff;border-radius:14px 14px 4px 14px;padding:7px 12px;font-size:12.5px;max-width:85%}.a{border:1px solid var(--line);border-radius:14px 14px 14px 4px;background:var(--surface);padding:10px 12px;font-size:13.5px;line-height:1.5;min-height:62px}.a .dots{display:inline-flex;gap:4px}.a .dots i{width:6px;height:6px;border-radius:50%;background:#bbb;animation:bl 1s infinite}.a .dots i:nth-child(2){animation-delay:.15s}.a .dots i:nth-child(3){animation-delay:.3s}@keyframes bl{50%{opacity:.25}}.bar{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--muted)}.ic{width:26px;height:26px;border-radius:50%;border:1px solid var(--line);background:var(--surface);font-size:16px;line-height:1}.ic:disabled{opacity:.35;cursor:default}.bar .mini{margin-left:auto}.out{font-size:12px;color:var(--muted);min-height:16px}.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){.a .dots i{animation:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const POOL=['Fresh beans, slow mornings.','Wake up to something good.','Where every cup has a story.','Brewed with care, served with a smile.','Your daily ritual, perfectly poured.'],MAX=5,an=document.getElementById('an'),ct=document.getElementById('ct'),pv=document.getElementById('pv'),nx=document.getElementById('nx'),rg=document.getElementById('rg'),out=document.getElementById('out'),calm=matchMedia('(prefers-reduced-motion:reduce)').matches;let V=[POOL[0]],cur=0,busy=false;
function up(){an.textContent=V[cur];ct.textContent=(cur+1)+' / '+V.length;pv.disabled=cur===0;nx.disabled=cur===V.length-1;rg.disabled=busy||V.length>=MAX;rg.textContent=V.length>=MAX?'Limit reached':'Regenerate';}
pv.addEventListener('click',()=>{cur=Math.max(0,cur-1);up();out.textContent='Showing version '+(cur+1)+'.';});nx.addEventListener('click',()=>{cur=Math.min(V.length-1,cur+1);up();out.textContent='Showing version '+(cur+1)+'.';});
rg.addEventListener('click',()=>{if(busy||V.length>=MAX)return;busy=true;out.textContent='Generating a new version\u2026';if(!calm)an.innerHTML='<span class="dots"><i></i><i></i><i></i></span>';rg.disabled=true;setTimeout(()=>{V.push(POOL[V.length]);cur=V.length-1;busy=false;up();out.textContent='New version added. Earlier versions are kept.';},calm?0:600);});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>Response Version Switcher — 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}
.q{align-self:end;justify-self:end;background:#171717;color:#fff;border-radius:14px 14px 4px 14px;padding:7px 12px;font-size:12.5px;max-width:85%}.a{border:1px solid var(--line);border-radius:14px 14px 14px 4px;background:var(--surface);padding:10px 12px;font-size:13.5px;line-height:1.5;min-height:62px}.a .dots{display:inline-flex;gap:4px}.a .dots i{width:6px;height:6px;border-radius:50%;background:#bbb;animation:bl 1s infinite}.a .dots i:nth-child(2){animation-delay:.15s}.a .dots i:nth-child(3){animation-delay:.3s}@keyframes bl{50%{opacity:.25}}.bar{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--muted)}.ic{width:26px;height:26px;border-radius:50%;border:1px solid var(--line);background:var(--surface);font-size:16px;line-height:1}.ic:disabled{opacity:.35;cursor:default}.bar .mini{margin-left:auto}.out{font-size:12px;color:var(--muted);min-height:16px}.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){.a .dots i{animation:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="q">Give me a tagline for a coffee shop.</div><div class="a" id="an" aria-live="polite"></div><div class="bar"><button class="ic" id="pv" type="button" aria-label="Previous version">‹</button><span id="ct">1 / 1</span><button class="ic" id="nx" type="button" aria-label="Next version">›</button><button class="mini" id="rg" type="button">Regenerate</button></div><p class="out" id="out" role="status"></p></div>
</div>
<script>
const POOL=['Fresh beans, slow mornings.','Wake up to something good.','Where every cup has a story.','Brewed with care, served with a smile.','Your daily ritual, perfectly poured.'],MAX=5,an=document.getElementById('an'),ct=document.getElementById('ct'),pv=document.getElementById('pv'),nx=document.getElementById('nx'),rg=document.getElementById('rg'),out=document.getElementById('out'),calm=matchMedia('(prefers-reduced-motion:reduce)').matches;let V=[POOL[0]],cur=0,busy=false;
function up(){an.textContent=V[cur];ct.textContent=(cur+1)+' / '+V.length;pv.disabled=cur===0;nx.disabled=cur===V.length-1;rg.disabled=busy||V.length>=MAX;rg.textContent=V.length>=MAX?'Limit reached':'Regenerate';}
pv.addEventListener('click',()=>{cur=Math.max(0,cur-1);up();out.textContent='Showing version '+(cur+1)+'.';});nx.addEventListener('click',()=>{cur=Math.min(V.length-1,cur+1);up();out.textContent='Showing version '+(cur+1)+'.';});
rg.addEventListener('click',()=>{if(busy||V.length>=MAX)return;busy=true;out.textContent='Generating a new version\u2026';if(!calm)an.innerHTML='<span class="dots"><i></i><i></i><i></i></span>';rg.disabled=true;setTimeout(()=>{V.push(POOL[V.length]);cur=V.length-1;busy=false;up();out.textContent='New version added. Earlier versions are kept.';},calm?0:600);});up();
</script>
</body></html>