# Pricing calculator

> Drag to your size and watch the price roll, the plan morph and, at the top, “Let’s talk”.

Usage-based pricing is hard to read from a table. Here people drag to their size and the answer comes to them. The thumb follows the finger with the fill and a value bubble riding along, and the price rolls digit by digit as it goes. Click the track or a mark and the thumb is thrown there with a little give. Crossing a tier morphs the plan’s name, lights the mark and changes the button’s words; past the last tier the price folds away and the line becomes "Let’s talk". With a yearly discount, a Monthly/Yearly switch rolls every figure to its yearly price. The formula is yours: pass price(value) and plan(value), on a linear or logarithmic scale.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/pricing-calculator.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`, `pricing-toggle`
- Docs and live preview: https://hairlineui.com/ui/pricing-calculator
- Registry item (source): https://hairlineui.com/r/pricing-calculator.json

## Usage

```tsx
import { PricingCalculator } from "@/components/pricing-calculator";

<PricingCalculator
  min={1_000}
  max={1_000_000}
  scale="log"
  unit="monthly active users"
  valueFormat={{ notation: "compact" }}
  price={(users) => 29 + users * 0.003}
  plan={(users) => (users < 10_000 ? "Starter" : "Growth")}
  marks={[{ value: 10_000, label: "10K" }]}
  contactFrom={500_000}
  yearlyDiscount={0.2}
/>
```

## In a pricing section

Above your plan cards, it answers "what would I pay?" before anyone reads a table.

```tsx
import { PricingCalculator } from "@/components/pricing-calculator";
import { price, plan, MARKS } from "@/lib/pricing";

export function Pricing() {
  return (
    <section className="mx-auto max-w-3xl px-6 py-24">
      <h2 className="text-4xl font-medium tracking-[-0.03em]">Pay for what you use</h2>
      <div className="mt-10 rounded-[22px] border border-border p-8">
        <PricingCalculator
          min={1_000}
          max={1_000_000}
          scale="log"
          unit="monthly active users"
          valueFormat={{ notation: "compact" }}
          price={price}
          plan={plan}
          marks={MARKS}
          contactFrom={500_000}
          yearlyDiscount={0.2}
          cta={{ label: (p) => `Start with ${p}`, onClick: (users, p, billing) => checkout({ users, plan: p, billing }) }}
        />
      </div>
    </section>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `min / max / step` | `number` | `— / — / 1` | The range. On a log scale the step grows with the value (thousands near 10K, ten-thousands near 100K). |
| `value / defaultValue / onValueChange` | `number` | – | Control it, or let it keep its own. |
| `price / plan` | `(value) => number / (value) => string` | – | Your monthly price and plan name for a value. |
| `marks` | `{ value; label }[]` | – | Ticks and labels along the track, e.g. where tiers change; clicking a label throws the thumb there. |
| `scale` | `"linear" \| "log"` | `"linear"` | Log spaces orders of magnitude evenly, so 1K, 10K and 100K get the same room. |
| `unit / valueFormat / currency` | `string / Intl.NumberFormatOptions / string` | `— / — / "USD"` | How the value and price read. |
| `locales` | `string \| string[]` | `the browser’s` | Locale for every figure. Set it when the page renders on a server, so the server and the browser format prices alike. |
| `contactFrom` | `number` | – | From this value, "Let’s talk" replaces the price. |
| `yearlyDiscount` | `number` | – | e.g. 0.2 adds a Monthly/Yearly switch with "Save 20%". |
| `cta` | `{ label(plan); contactLabel?; onClick?(value, plan, billing) }` | – | The button under the price; its words follow the plan. |

## States

- **drag**: The thumb, fill and value bubble track the pointer exactly; the price and the value roll (300ms while dragging).
- **jump**: A press on the track, a mark’s label, Page Up/Down, Home or End throws the thumb to the new value over 520ms with a slight overshoot.
- **tier**: Crossing a mark morphs the plan name and the button’s words and turns the mark white on the fill.
- **contact**: At contactFrom the price folds to nothing through a 6px blur as "Let’s talk" opens in its place and the button turns to an outline "Contact sales".
- **yearly**: The switch is thrown to Yearly; the monthly figure rolls down by the discount and the line under it morphs to "$2,995 billed yearly".

## What it handles

Usage-based pricing is hard to read from a table. People want to say “I have 25,000 users” and see what they would pay. They drag to their size and the answer comes to them.

- **Drag to your size**: The thumb follows the pointer with the fill and a value bubble, and the price rolls digit by digit.
- **Your own formula**: Pass price(value) and plan(value) and the calculator does the rest.
- **Linear or logarithmic**: A log scale gives 1K, 10K and 100K the same room on the track.
- **Tier marks**: Click a mark to throw the thumb there. Crossing a tier morphs the plan name and the button’s words.
- **“Let’s talk” at the top**: From the value you choose, the price folds away and the button becomes Contact sales.
- **Monthly and yearly**: Set a yearly discount and a switch rolls every figure. The slider reads out as “25K monthly active users, $96 a month”.

## Replaces

a pricing slider, price display code, tier name logic, a billing switch, a contact sales state, a log scale

## Where it fits

- **Usage-based pricing**: Prices that depend on API calls, seats, emails or monthly active users.
- **SaaS pricing pages**: A slider above the plan cards that answers “what would I pay?”.
- **Sales-led top tiers**: Past a certain size the price becomes “Let’s talk” and the button reads Contact sales.
- **Cost estimators**: Storage, bandwidth or compute estimates before someone signs up.

## Notes

- The thumb is a real slider: Arrow keys nudge, Page Up/Down move a tenth, Home and End jump to the ends. Its value text reads the size and the price ("25K monthly active users, $96 a month").
- The plan is announced politely as you cross a tier; the rolling digits are hidden from screen readers.
- Pointer events with capture, so dragging works with mouse, pen and touch and keeps working outside the track.
- Installs Number roll, Text morph and Pricing toggle. With reduced motion the thumb and figures move in place.

License: MIT (https://hairlineui.com/license#components)
