Usage pricing calculator
Drag a seat slider and flip add-ons to watch the monthly price roll like an odometer, with a breakdown that explains every dollar.
"use client";
import { useState, type CSSProperties } from "react";
import "./pricing-calculator.css";
const ADDONS = [
{ id: "sso", label: "Single sign-on", price: 4, per: "seat" as const },
{
id: "archive",
label: "Unlimited archive",
price: 49,
per: "month" as const,
},
{
id: "support",
label: "Priority support",
price: 99,
per: "month" as const,
},
];
const MAX_SEATS = 200;
/** Price per seat drops in tiers. Edit to match your pricing. */
const seatPrice = (n: number) => (n <= 10 ? 12 : n <= 50 ? 10 : 8);
/** Each digit is a vertical strip 0–9 that slides to the right number. */
function Rolling({ value }: { value: number }) {
const text = value.toLocaleString("en-US");
return (
<span className="gu-calc__num" aria-hidden="true">
{text.split("").map((ch, i) =>
/\d/.test(ch) ? (
<span
key={text.length - i}
className="gu-calc__digit"
style={{ "--d": Number(ch) } as CSSProperties}
>
<span>0123456789</span>
</span>
) : (
<span key={`s${text.length - i}`}>{ch}</span>
),
)}
</span>
);
}
/**
* PricingCalculator
* - Total = seats × tier price + add-ons, with yearly billing taking 2 months off.
* - The visible number is decorative; a screen-reader-only sentence carries the real total.
*/
export function PricingCalculator({
theme = "light",
}: {
theme?: "light" | "dark";
}) {
const [seats, setSeats] = useState(24);
const [on, setOn] = useState<Record<string, boolean>>({ sso: true });
const [yearly, setYearly] = useState(false);
const base = seats * seatPrice(seats);
const extras = ADDONS.filter((a) => on[a.id]).map((a) => ({
...a,
cost: a.per === "seat" ? a.price * seats : a.price,
}));
const monthly = base + extras.reduce((s, a) => s + a.cost, 0);
const total = yearly ? Math.round((monthly * 10) / 12) : monthly;
return (
<div
className="gu-calc"
data-theme={theme}
style={{ "--fill": `${(seats / MAX_SEATS) * 100}%` } as CSSProperties}
>
<div className="gu-calc__controls">
<label className="gu-calc__seats" htmlFor="gu-calc-seats">
<span>Team size</span>
<b>{seats} seats</b>
</label>
<input
id="gu-calc-seats"
type="range"
min={1}
max={MAX_SEATS}
value={seats}
onChange={(e) => setSeats(Number(e.target.value))}
aria-valuetext={`${seats} seats`}
/>
<div className="gu-calc__tiers" aria-hidden="true">
<span>$12 / seat</span>
<span>$10 after 10</span>
<span>$8 after 50</span>
</div>
<fieldset className="gu-calc__addons">
<legend>Add-ons</legend>
{ADDONS.map((a) => (
<label key={a.id}>
<input
type="checkbox"
checked={!!on[a.id]}
onChange={(e) =>
setOn((o) => ({ ...o, [a.id]: e.target.checked }))
}
/>
<span className="gu-calc__box" aria-hidden="true" />
<span className="gu-calc__name">{a.label}</span>
<span className="gu-calc__cost">
+${a.price} / {a.per}
</span>
</label>
))}
</fieldset>
</div>
<div className="gu-calc__total">
<div className="gu-calc__bill" role="group" aria-label="Billing">
<button
type="button"
aria-pressed={!yearly}
onClick={() => setYearly(false)}
>
Monthly
</button>
<button
type="button"
aria-pressed={yearly}
onClick={() => setYearly(true)}
>
Yearly · 2 months free
</button>
</div>
<p className="gu-calc__price">
<span className="gu-calc__cur">$</span>
<Rolling value={total} />
<span className="gu-calc__per">/ mo</span>
</p>
<p className="gu-sr" aria-live="polite">
Total {total} dollars per month
</p>
<ul className="gu-calc__lines">
<li>
<span>
{seats} seats × ${seatPrice(seats)}
</span>
<b>${base.toLocaleString("en-US")}</b>
</li>
{extras.map((a) => (
<li key={a.id}>
<span>{a.label}</span>
<b>${a.cost.toLocaleString("en-US")}</b>
</li>
))}
{yearly && (
<li className="gu-calc__save">
<span>Yearly saving</span>
<b>−${(monthly - total).toLocaleString("en-US")}</b>
</li>
)}
</ul>
<a href="#start" className="gu-calc__cta">
Start a 14-day trial
</a>
</div>
</div>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Usage pricing calculator
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A usage-based pricing calculator: a seat slider with tiered per-seat pricing, add-on checkboxes and a monthly/yearly switch. The total rolls like an odometer and a breakdown explains each line.
## Layout and look
- Two-column card (860px max, radius 28px): controls on a light panel, totals on an Ink panel (inverted in dark mode). Stacks under 640px container width.
- Slider: 8px track filled orange to the thumb, 32px Ink thumb with a thick card-colored ring. "24 seats" in big bold digits. Tier hints under the track.
- Add-ons: 52px rows with a custom 22px checkbox (orange with a dark check when on), name and "+$4 / seat" price; selected rows get an orange border and tint.
- Totals: pill billing switch, "$" + giant rolling number (clamp 51–80px, weight 900) + "/ mo", hairline, breakdown rows (muted label, bold value), "Yearly saving" in a lime chip, orange 54px CTA.
## Behavior and motion
1. Seat price tiers: $12 up to 10 seats, $10 up to 50, $8 above. Add-ons are per seat or per month. Yearly = 10/12 of monthly.
2. Each digit is a 0–9 vertical strip translated by -digit em (700ms cubic-bezier(0.16, 1, 0.3, 1)).
3. Breakdown rows slide in when added.
## Touch
32px thumb, 52px rows.
## Accessibility
- Native range with aria-valuetext; real checkboxes in a fieldset; billing buttons with aria-pressed.
- The rolling number is aria-hidden; a polite live region reads "Total 312 dollars per month".
- prefers-reduced-motion: no rolling.
## Props
theme. Edit ADDONS, seatPrice and MAX_SEATS.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### PricingCalculator.tsx
```tsx
"use client";
import { useState, type CSSProperties } from "react";
import "./pricing-calculator.css";
const ADDONS = [
{ id: "sso", label: "Single sign-on", price: 4, per: "seat" as const },
{
id: "archive",
label: "Unlimited archive",
price: 49,
per: "month" as const,
},
{
id: "support",
label: "Priority support",
price: 99,
per: "month" as const,
},
];
const MAX_SEATS = 200;
/** Price per seat drops in tiers. Edit to match your pricing. */
const seatPrice = (n: number) => (n <= 10 ? 12 : n <= 50 ? 10 : 8);
/** Each digit is a vertical strip 0–9 that slides to the right number. */
function Rolling({ value }: { value: number }) {
const text = value.toLocaleString("en-US");
return (
<span className="gu-calc__num" aria-hidden="true">
{text.split("").map((ch, i) =>
/\d/.test(ch) ? (
<span
key={text.length - i}
className="gu-calc__digit"
style={{ "--d": Number(ch) } as CSSProperties}
>
<span>0123456789</span>
</span>
) : (
<span key={`s${text.length - i}`}>{ch}</span>
),
)}
</span>
);
}
/**
* PricingCalculator
* - Total = seats × tier price + add-ons, with yearly billing taking 2 months off.
* - The visible number is decorative; a screen-reader-only sentence carries the real total.
*/
export function PricingCalculator({
theme = "light",
}: {
theme?: "light" | "dark";
}) {
const [seats, setSeats] = useState(24);
const [on, setOn] = useState<Record<string, boolean>>({ sso: true });
const [yearly, setYearly] = useState(false);
const base = seats * seatPrice(seats);
const extras = ADDONS.filter((a) => on[a.id]).map((a) => ({
...a,
cost: a.per === "seat" ? a.price * seats : a.price,
}));
const monthly = base + extras.reduce((s, a) => s + a.cost, 0);
const total = yearly ? Math.round((monthly * 10) / 12) : monthly;
return (
<div
className="gu-calc"
data-theme={theme}
style={{ "--fill": `${(seats / MAX_SEATS) * 100}%` } as CSSProperties}
>
<div className="gu-calc__controls">
<label className="gu-calc__seats" htmlFor="gu-calc-seats">
<span>Team size</span>
<b>{seats} seats</b>
</label>
<input
id="gu-calc-seats"
type="range"
min={1}
max={MAX_SEATS}
value={seats}
onChange={(e) => setSeats(Number(e.target.value))}
aria-valuetext={`${seats} seats`}
/>
<div className="gu-calc__tiers" aria-hidden="true">
<span>$12 / seat</span>
<span>$10 after 10</span>
<span>$8 after 50</span>
</div>
<fieldset className="gu-calc__addons">
<legend>Add-ons</legend>
{ADDONS.map((a) => (
<label key={a.id}>
<input
type="checkbox"
checked={!!on[a.id]}
onChange={(e) =>
setOn((o) => ({ ...o, [a.id]: e.target.checked }))
}
/>
<span className="gu-calc__box" aria-hidden="true" />
<span className="gu-calc__name">{a.label}</span>
<span className="gu-calc__cost">
+${a.price} / {a.per}
</span>
</label>
))}
</fieldset>
</div>
<div className="gu-calc__total">
<div className="gu-calc__bill" role="group" aria-label="Billing">
<button
type="button"
aria-pressed={!yearly}
onClick={() => setYearly(false)}
>
Monthly
</button>
<button
type="button"
aria-pressed={yearly}
onClick={() => setYearly(true)}
>
Yearly · 2 months free
</button>
</div>
<p className="gu-calc__price">
<span className="gu-calc__cur">$</span>
<Rolling value={total} />
<span className="gu-calc__per">/ mo</span>
</p>
<p className="gu-sr" aria-live="polite">
Total {total} dollars per month
</p>
<ul className="gu-calc__lines">
<li>
<span>
{seats} seats × ${seatPrice(seats)}
</span>
<b>${base.toLocaleString("en-US")}</b>
</li>
{extras.map((a) => (
<li key={a.id}>
<span>{a.label}</span>
<b>${a.cost.toLocaleString("en-US")}</b>
</li>
))}
{yearly && (
<li className="gu-calc__save">
<span>Yearly saving</span>
<b>−${(monthly - total).toLocaleString("en-US")}</b>
</li>
)}
</ul>
<a href="#start" className="gu-calc__cta">
Start a 14-day trial
</a>
</div>
</div>
);
}
```
### pricing-calculator.css
```css
/* PricingCalculator: change these colors to match your brand. */
.gu-calc {
--card: #fbf8f2;
--text: #0e0e10;
--muted: #57534b;
--line: rgb(14 14 16 / 0.14);
--dark: #0e0e10;
--on-dark: #f3eee3;
--on-dark-muted: #aea89c;
--accent: #ff5a1f;
--volt: #d7ff3a;
--focus: #2b35ff;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
container-type: inline-size;
display: grid;
grid-template-columns: 1.1fr 1fr;
width: min(100%, 860px);
overflow: hidden;
border: 1px solid var(--line);
border-radius: 28px;
background: var(--card);
color: var(--text);
font-family: system-ui, sans-serif;
}
.gu-calc[data-theme="dark"] {
--card: #18181b;
--text: #f3eee3;
--muted: #aea89c;
--line: rgb(243 238 227 / 0.14);
--dark: #f3eee3;
--on-dark: #0e0e10;
--on-dark-muted: #57534b;
--focus: #d7ff3a;
}
.gu-calc__controls {
display: grid;
align-content: start;
gap: 12px;
padding: clamp(20px, 4cqi, 36px);
}
.gu-calc__seats {
display: flex;
justify-content: space-between;
align-items: baseline;
font-weight: 700;
}
.gu-calc__seats b {
font-size: 1.6rem;
font-weight: 900;
letter-spacing: -0.03em;
font-variant-numeric: tabular-nums;
}
.gu-calc input[type="range"] {
width: 100%;
height: 32px;
margin: 0;
background: none;
appearance: none;
-webkit-appearance: none;
cursor: pointer;
}
.gu-calc input[type="range"]::-webkit-slider-runnable-track {
height: 8px;
border-radius: 8px;
background:
linear-gradient(var(--accent), var(--accent)) 0 / var(--fill) 100% no-repeat,
var(--line);
}
.gu-calc input[type="range"]::-moz-range-track {
height: 8px;
border-radius: 8px;
background: var(--line);
}
.gu-calc input[type="range"]::-moz-range-progress {
height: 8px;
border-radius: 8px;
background: var(--accent);
}
.gu-calc input[type="range"]::-webkit-slider-thumb {
width: 32px;
height: 32px;
margin-top: -12px;
border: 5px solid var(--card);
border-radius: 50%;
background: var(--text);
box-shadow: 0 0 0 1.5px var(--text);
-webkit-appearance: none;
}
.gu-calc input[type="range"]::-moz-range-thumb {
width: 22px;
height: 22px;
border: 5px solid var(--card);
border-radius: 50%;
background: var(--text);
}
.gu-calc input:focus-visible {
outline: 3px solid var(--focus);
outline-offset: 4px;
border-radius: 8px;
}
.gu-calc__tiers {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 0.75rem;
font-weight: 600;
}
.gu-calc__addons {
display: grid;
gap: 4px;
margin: 14px 0 0;
padding: 0;
border: 0;
}
.gu-calc__addons legend {
margin-bottom: 6px;
font-weight: 800;
}
.gu-calc__addons label {
position: relative;
display: grid;
grid-template-columns: 24px 1fr auto;
align-items: center;
gap: 12px;
min-height: 52px;
padding: 0 12px;
border: 1px solid var(--line);
border-radius: 14px;
cursor: pointer;
transition:
border-color 0.2s,
background-color 0.2s;
}
.gu-calc__addons label:has(input:checked) {
border-color: var(--accent);
background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.gu-calc__addons input {
position: absolute;
opacity: 0;
}
.gu-calc__box {
width: 22px;
height: 22px;
border: 2px solid var(--line);
border-radius: 7px;
transition:
background-color 0.2s,
border-color 0.2s;
}
.gu-calc__addons input:checked + .gu-calc__box {
border-color: var(--accent);
background: var(--accent)
url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='m5 10.5 3.2 3.2L15 6.5' fill='none' stroke='%230e0e10' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
center / 16px no-repeat;
}
.gu-calc__addons input:focus-visible + .gu-calc__box {
outline: 3px solid var(--focus);
outline-offset: 2px;
}
.gu-calc__name {
font-weight: 700;
}
.gu-calc__cost {
color: var(--muted);
font-size: 0.82rem;
font-weight: 600;
}
.gu-calc__total {
display: grid;
align-content: start;
gap: 14px;
padding: clamp(20px, 4cqi, 36px);
background: var(--dark);
color: var(--on-dark);
}
.gu-calc__bill {
display: flex;
padding: 4px;
border-radius: 999px;
background: color-mix(in srgb, var(--on-dark) 10%, transparent);
}
.gu-calc__bill button {
flex: 1;
min-height: 38px;
border: 0;
border-radius: 999px;
background: none;
color: var(--on-dark-muted);
font: inherit;
font-size: 0.82rem;
font-weight: 700;
cursor: pointer;
}
.gu-calc__bill [aria-pressed="true"] {
background: var(--on-dark);
color: var(--dark);
}
.gu-calc__bill button:focus-visible,
.gu-calc__cta:focus-visible {
outline: 3px solid var(--volt);
outline-offset: 2px;
}
.gu-calc__price {
display: flex;
align-items: flex-start;
margin: 8px 0 0;
font-weight: 900;
line-height: 1;
}
.gu-calc__cur {
margin-top: 0.3em;
font-size: 1.6rem;
}
.gu-calc__num {
display: inline-flex;
font-size: clamp(3.2rem, 11cqi, 5rem);
letter-spacing: -0.05em;
font-variant-numeric: tabular-nums;
}
.gu-calc__digit {
display: inline-block;
height: 1em;
overflow: hidden;
}
.gu-calc__digit span {
display: block;
width: 0.62em;
line-height: 1;
word-break: break-all;
transform: translateY(calc(var(--d) * -1em));
transition: transform 0.7s var(--ease);
}
.gu-calc__per {
align-self: flex-end;
margin: 0 0 0.5em 6px;
color: var(--on-dark-muted);
font-size: 1rem;
}
.gu-calc__lines {
display: grid;
gap: 8px;
margin: 4px 0 6px;
padding: 14px 0 0;
border-top: 1px solid color-mix(in srgb, var(--on-dark) 18%, transparent);
list-style: none;
font-size: 0.88rem;
}
.gu-calc__lines li {
display: flex;
justify-content: space-between;
gap: 12px;
color: var(--on-dark-muted);
animation: gu-calc-line 0.35s var(--ease);
}
.gu-calc__lines b {
color: var(--on-dark);
font-variant-numeric: tabular-nums;
}
.gu-calc__save b {
padding: 0 6px;
border-radius: 6px;
background: var(--volt);
color: #0e0e10;
}
@keyframes gu-calc-line {
from {
opacity: 0;
transform: translateY(-6px);
}
}
.gu-calc__cta {
display: grid;
place-items: center;
min-height: 54px;
border-radius: 999px;
background: var(--accent);
color: #0e0e10;
font-weight: 800;
text-decoration: none;
transition: transform 0.2s;
}
.gu-calc__cta:hover {
transform: translateY(-2px);
}
.gu-sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
@container (max-width: 640px) {
/* The root is the container, so it cannot query itself: its children span the full row instead */
.gu-calc > * {
grid-column: 1 / -1;
}
}
@media (prefers-reduced-motion: reduce) {
.gu-calc__digit span,
.gu-calc__lines li,
.gu-calc__cta {
transition: none;
animation: none;
}
}
```
You might also want
Next piece: Writer portfolioPricing comparison table
Templates, intermediate
Pricing section
Templates, intermediate
Public roadmap
Templates, intermediate