Pricing Toggle Card
A plan card with a Monthly/Yearly switch; the price rolls to the new value and a savings badge appears.
AI prompt
Design a pricing plan card for "Pro" with a billing switch above the price. A pill switch (role switch, aria-checked) labelled "Monthly" and "Yearly" toggles billing; when Yearly is on, a small green badge "Save 20%" scales in next to the label. The large price shows "$12" per month for Monthly and "$9.60" per month for Yearly, with the line "Billed $115.20 yearly" beneath it in grey; the number animates (counts) to the new value over about 350 milliseconds using tabular numerals. Below, a list of three features with check icons and a near-black full-width "Choose Pro" button. Light card, 16 pixel radius, 1 pixel border, minimal style, prefers-reduced-motion fallback. Plain HTML, CSS and JavaScript.About this pattern
Definition
A pricing card presents one plan with its price and features. A billing switch lets people compare monthly and yearly cost without leaving the card.
Purpose & UX principles
- Show the effective monthly price for both options and say what is billed ("$115 billed yearly") so nothing is hidden.
- Make the saving explicit with a small badge ("Save 20%"); animate the price briefly so the change is noticed.
- The switch must be a real control with a label and role switch, reachable by keyboard.
Interaction states
- Monthly (default), Yearly (badge visible), focus on switch, pressed.
Motion specification
- The price counts to its new value over 350ms; the badge scales in 150ms.
- Reduced motion: the price changes instantly and the badge appears without scaling.
Responsive behaviour
- The card keeps a 280px max width; stack plan cards vertically on phones.
- Price uses tabular numbers so digits do not jitter while animating.
Code
<div class="cd"><div class="hd"><span class="pl">Pro</span><span class="bd" id="bd" hidden>Save 20%</span></div>
<div class="sw"><span id="lm" class="on">Monthly</span><button id="tg" type="button" role="switch" aria-checked="false" aria-label="Bill yearly"><i></i></button><span id="ly">Yearly</span></div>
<div class="pr"><b id="pv">$12.00</b><span>/month</span></div><p class="bl" id="bl">Billed monthly</p>
<ul><li>Unlimited projects</li><li>Priority support</li><li>Export in any format</li></ul><button class="cta" type="button">Choose Pro</button></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}
.cd{width:min(270px,100%);padding:18px;border-radius:16px;background:var(--surface);border:1px solid var(--line);display:grid;gap:10px}
.hd{display:flex;justify-content:space-between;align-items:center;min-height:22px}.pl{font-weight:700}
.bd{font-size:11px;font-weight:700;color:#1a6d3a;background:#e2f5e8;padding:2px 8px;border-radius:99px;animation:sc .15s ease-out}
@keyframes sc{from{transform:scale(.6);opacity:0}}
.sw{display:flex;align-items:center;gap:10px;font-size:12.5px;color:var(--muted)}.sw .on{color:var(--text);font-weight:600}
#tg{width:42px;height:24px;border-radius:99px;border:0;background:#d4d4cf;position:relative;cursor:pointer;transition:background .15s}
#tg i{position:absolute;left:3px;top:3px;width:18px;height:18px;border-radius:50%;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.25);transition:transform .15s}
#tg[aria-checked=true]{background:var(--text)}#tg[aria-checked=true] i{transform:translateX(18px)}
.pr{display:flex;align-items:baseline;gap:4px}.pr b{font-size:34px;letter-spacing:-.02em;font-variant-numeric:tabular-nums}.pr span{font-size:13px;color:var(--muted)}
.bl{font-size:12px;color:var(--muted);margin-top:-6px}
ul{list-style:none;padding:0;display:grid;gap:5px;font-size:13px}li::before{content:"✓";font-weight:700;margin-right:8px}
.cta{height:38px;border-radius:99px;border:0;background:var(--accent);color:var(--accent-ink);font-size:13.5px;font-weight:600;cursor:pointer}
button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.bd{animation:none}#tg,#tg i{transition:none}}const $=id=>document.getElementById(id),tg=$('tg'),pv=$('pv'),bd=$('bd'),bl=$('bl'),lm=$('lm'),ly=$('ly'),reduce=matchMedia('(prefers-reduced-motion: reduce)').matches;let cur=12,raf=0;
function show(v){pv.textContent='$'+v.toFixed(2);}
function tween(to){cancelAnimationFrame(raf);if(reduce){cur=to;show(to);return;}const from=cur,t0=performance.now();(function f(n){const k=Math.min(1,(n-t0)/350),e=1-Math.pow(1-k,3);cur=from+(to-from)*e;show(cur);if(k<1)raf=requestAnimationFrame(f);})(t0);}
tg.addEventListener('click',()=>{const y=tg.getAttribute('aria-checked')!=='true';tg.setAttribute('aria-checked',String(y));bd.hidden=!y;lm.className=y?'':'on';ly.className=y?'on':'';bl.textContent=y?'Billed $115.20 yearly':'Billed monthly';tween(y?9.6:12);});
show(12);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>Pricing Toggle Card — 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}}
.cd{width:min(270px,100%);padding:18px;border-radius:16px;background:var(--surface);border:1px solid var(--line);display:grid;gap:10px}
.hd{display:flex;justify-content:space-between;align-items:center;min-height:22px}.pl{font-weight:700}
.bd{font-size:11px;font-weight:700;color:#1a6d3a;background:#e2f5e8;padding:2px 8px;border-radius:99px;animation:sc .15s ease-out}
@keyframes sc{from{transform:scale(.6);opacity:0}}
.sw{display:flex;align-items:center;gap:10px;font-size:12.5px;color:var(--muted)}.sw .on{color:var(--text);font-weight:600}
#tg{width:42px;height:24px;border-radius:99px;border:0;background:#d4d4cf;position:relative;cursor:pointer;transition:background .15s}
#tg i{position:absolute;left:3px;top:3px;width:18px;height:18px;border-radius:50%;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.25);transition:transform .15s}
#tg[aria-checked=true]{background:var(--text)}#tg[aria-checked=true] i{transform:translateX(18px)}
.pr{display:flex;align-items:baseline;gap:4px}.pr b{font-size:34px;letter-spacing:-.02em;font-variant-numeric:tabular-nums}.pr span{font-size:13px;color:var(--muted)}
.bl{font-size:12px;color:var(--muted);margin-top:-6px}
ul{list-style:none;padding:0;display:grid;gap:5px;font-size:13px}li::before{content:"✓";font-weight:700;margin-right:8px}
.cta{height:38px;border-radius:99px;border:0;background:var(--accent);color:var(--accent-ink);font-size:13.5px;font-weight:600;cursor:pointer}
button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.bd{animation:none}#tg,#tg i{transition:none}}
</style></head>
<body><div class="stage">
<div class="cd"><div class="hd"><span class="pl">Pro</span><span class="bd" id="bd" hidden>Save 20%</span></div>
<div class="sw"><span id="lm" class="on">Monthly</span><button id="tg" type="button" role="switch" aria-checked="false" aria-label="Bill yearly"><i></i></button><span id="ly">Yearly</span></div>
<div class="pr"><b id="pv">$12.00</b><span>/month</span></div><p class="bl" id="bl">Billed monthly</p>
<ul><li>Unlimited projects</li><li>Priority support</li><li>Export in any format</li></ul><button class="cta" type="button">Choose Pro</button></div>
</div>
<script>
const $=id=>document.getElementById(id),tg=$('tg'),pv=$('pv'),bd=$('bd'),bl=$('bl'),lm=$('lm'),ly=$('ly'),reduce=matchMedia('(prefers-reduced-motion: reduce)').matches;let cur=12,raf=0;
function show(v){pv.textContent='$'+v.toFixed(2);}
function tween(to){cancelAnimationFrame(raf);if(reduce){cur=to;show(to);return;}const from=cur,t0=performance.now();(function f(n){const k=Math.min(1,(n-t0)/350),e=1-Math.pow(1-k,3);cur=from+(to-from)*e;show(cur);if(k<1)raf=requestAnimationFrame(f);})(t0);}
tg.addEventListener('click',()=>{const y=tg.getAttribute('aria-checked')!=='true';tg.setAttribute('aria-checked',String(y));bd.hidden=!y;lm.className=y?'':'on';ly.className=y?'on':'';bl.textContent=y?'Billed $115.20 yearly':'Billed monthly';tween(y?9.6:12);});
show(12);
</script>
</body></html>