Sparkline Trend Rows
Compact trend lines beside each metric; hovering a line replaces the number with that point's value.
AI prompt
Create three metric rows (Revenue, Users, Churn) in a 300px wide card, each 52px tall with three columns: a label with a small delta text (+8.2%, +3.1%, -0.4%), a 100x28px SVG sparkline of 12 points and the current value (right aligned, 14px semibold). Draw each sparkline as a 1.5px polyline with no axes and animate it drawing over 700ms ease-out using stroke-dasharray. On pointermove over a sparkline find the nearest point, draw a 4px dot there and replace the displayed value with that point's value; on pointerleave restore the latest value. Support touch dragging with touch-action pan-y. Rows are focusable and ArrowLeft and ArrowRight move through the points while focused. Delta text uses a plus or minus sign, plus a colour: green for good and red for bad (churn down is good). Under prefers-reduced-motion skip the drawing.About this pattern
Definition
A tiny line chart without axes, placed next to a metric. It shows the shape of change at a glance, and hovering it reveals the value at that point.
Purpose & UX principles
- Packs trend and current value into one row, ideal for dashboards and tables.
- The number is always the source of truth; the line adds context.
- Direction is also written as text (+8.2%) so it is not carried by colour alone.
Interaction states
- Rest (latest value), hover or drag (value of the nearest point and a dot), focus-visible ring on the row.
Motion specification
- The line draws in 700ms ease-out on load.
- The value updates immediately while hovering.
- Reduced motion: lines appear drawn.
Responsive behaviour
- Each sparkline fills the middle column; rows stay at 52px tall.
- On touch, dragging across the line updates the value.
Code
<div class="card" id="card"></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}
.card{width:min(300px,100%);background:var(--surface);border:1px solid var(--line);border-radius:14px;overflow:hidden}
.row{display:grid;grid-template-columns:84px 1fr 62px;align-items:center;gap:10px;height:52px;padding:0 14px;border-top:1px solid var(--line)}
.row:first-child{border-top:0}
.row:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}
.lb b{display:block;font-size:12.5px;font-weight:600}
.lb small{font-size:11px;font-weight:600}
.up{color:#1a7f4b}.dn{color:#d92d20}
.sp{width:100%;height:28px;touch-action:pan-y;cursor:crosshair;overflow:visible}
.ln{fill:none;stroke:#171717;stroke-width:1.5;stroke-linejoin:round;stroke-linecap:round;stroke-dasharray:var(--len);animation:dr .7s ease-out}
@keyframes dr{from{stroke-dashoffset:var(--len)}}
.dt{fill:#171717;opacity:0}.row.hv .dt{opacity:1}
.val{text-align:right;font-size:14px;font-weight:600;font-variant-numeric:tabular-nums}
@media (prefers-reduced-motion:reduce){.ln{animation:none}}const S=[['Revenue','+8.2%',1,[40,42,41,46,44,49,52,50,55,58,57,62],v=>'$'+v+'k'],['Users','+3.1%',1,[120,126,124,131,135,133,140,146,144,150,153,158],v=>(v*10).toLocaleString()],['Churn','-0.4%',1,[4.8,4.9,4.7,4.8,4.6,4.5,4.6,4.4,4.5,4.3,4.4,4.4],v=>v+'%']];
const card=document.getElementById('card');
S.forEach(([n,dl,good,d,f])=>{const row=document.createElement('div');row.className='row';row.tabIndex=0;row.setAttribute('aria-label',n+', latest '+f(d[11])+', '+dl);
const mn=Math.min(...d),mx=Math.max(...d),X=i=>i*100/11,Y=v=>26-(v-mn)/(mx-mn||1)*24;
row.innerHTML='<div class="lb"><b>'+n+'</b><small class="'+(good?'up':'dn')+'">'+dl+'</small></div><svg class="sp" viewBox="0 0 100 28" preserveAspectRatio="none" aria-hidden="true"><polyline class="ln" points="'+d.map((v,i)=>X(i).toFixed(1)+','+Y(v).toFixed(1)).join(' ')+'"/><circle class="dt" r="2.5"/></svg><div class="val">'+f(d[11])+'</div>';
card.append(row);const sp=row.querySelector('svg'),ln=row.querySelector('.ln'),dt=row.querySelector('.dt'),val=row.querySelector('.val');ln.style.setProperty('--len',Math.ceil(ln.getTotalLength())+1);
let idx=11;const show=(i,on)=>{idx=i;row.classList.toggle('hv',on);dt.setAttribute('cx',X(i));dt.setAttribute('cy',Y(d[i]));val.textContent=f(d[i]);};
const near=e=>{const r=sp.getBoundingClientRect();return Math.max(0,Math.min(11,Math.round((e.clientX-r.left)/r.width*11)));};
sp.addEventListener('pointermove',e=>show(near(e),true));sp.addEventListener('pointerdown',e=>show(near(e),true));sp.addEventListener('pointerleave',()=>show(11,false));
row.addEventListener('keydown',e=>{if(e.key==='ArrowLeft'){e.preventDefault();show(Math.max(0,idx-1),true);}if(e.key==='ArrowRight'){e.preventDefault();show(Math.min(11,idx+1),true);}});
row.addEventListener('blur',()=>show(11,false));});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>Sparkline Trend Rows — 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}}
.card{width:min(300px,100%);background:var(--surface);border:1px solid var(--line);border-radius:14px;overflow:hidden}
.row{display:grid;grid-template-columns:84px 1fr 62px;align-items:center;gap:10px;height:52px;padding:0 14px;border-top:1px solid var(--line)}
.row:first-child{border-top:0}
.row:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}
.lb b{display:block;font-size:12.5px;font-weight:600}
.lb small{font-size:11px;font-weight:600}
.up{color:#1a7f4b}.dn{color:#d92d20}
.sp{width:100%;height:28px;touch-action:pan-y;cursor:crosshair;overflow:visible}
.ln{fill:none;stroke:#171717;stroke-width:1.5;stroke-linejoin:round;stroke-linecap:round;stroke-dasharray:var(--len);animation:dr .7s ease-out}
@keyframes dr{from{stroke-dashoffset:var(--len)}}
.dt{fill:#171717;opacity:0}.row.hv .dt{opacity:1}
.val{text-align:right;font-size:14px;font-weight:600;font-variant-numeric:tabular-nums}
@media (prefers-reduced-motion:reduce){.ln{animation:none}}
</style></head>
<body><div class="stage">
<div class="card" id="card"></div>
</div>
<script>
const S=[['Revenue','+8.2%',1,[40,42,41,46,44,49,52,50,55,58,57,62],v=>'$'+v+'k'],['Users','+3.1%',1,[120,126,124,131,135,133,140,146,144,150,153,158],v=>(v*10).toLocaleString()],['Churn','-0.4%',1,[4.8,4.9,4.7,4.8,4.6,4.5,4.6,4.4,4.5,4.3,4.4,4.4],v=>v+'%']];
const card=document.getElementById('card');
S.forEach(([n,dl,good,d,f])=>{const row=document.createElement('div');row.className='row';row.tabIndex=0;row.setAttribute('aria-label',n+', latest '+f(d[11])+', '+dl);
const mn=Math.min(...d),mx=Math.max(...d),X=i=>i*100/11,Y=v=>26-(v-mn)/(mx-mn||1)*24;
row.innerHTML='<div class="lb"><b>'+n+'</b><small class="'+(good?'up':'dn')+'">'+dl+'</small></div><svg class="sp" viewBox="0 0 100 28" preserveAspectRatio="none" aria-hidden="true"><polyline class="ln" points="'+d.map((v,i)=>X(i).toFixed(1)+','+Y(v).toFixed(1)).join(' ')+'"/><circle class="dt" r="2.5"/></svg><div class="val">'+f(d[11])+'</div>';
card.append(row);const sp=row.querySelector('svg'),ln=row.querySelector('.ln'),dt=row.querySelector('.dt'),val=row.querySelector('.val');ln.style.setProperty('--len',Math.ceil(ln.getTotalLength())+1);
let idx=11;const show=(i,on)=>{idx=i;row.classList.toggle('hv',on);dt.setAttribute('cx',X(i));dt.setAttribute('cy',Y(d[i]));val.textContent=f(d[i]);};
const near=e=>{const r=sp.getBoundingClientRect();return Math.max(0,Math.min(11,Math.round((e.clientX-r.left)/r.width*11)));};
sp.addEventListener('pointermove',e=>show(near(e),true));sp.addEventListener('pointerdown',e=>show(near(e),true));sp.addEventListener('pointerleave',()=>show(11,false));
row.addEventListener('keydown',e=>{if(e.key==='ArrowLeft'){e.preventDefault();show(Math.max(0,idx-1),true);}if(e.key==='ArrowRight'){e.preventDefault();show(Math.min(11,idx+1),true);}});
row.addEventListener('blur',()=>show(11,false));});
</script>
</body></html>