# Pricing toggle

> Monthly or yearly: the thumb slides with a little give, and every price on the page rolls to its new amount.

The billing switch is the one control every pricing page has, and usually the dullest. Here the thumb slides and resizes to the chosen option with a little give at the end, and the labels trade colour. "Save 20%" sits inside Yearly and lights up in your brand colour when it’s chosen. Every Price on the page rolls digit by digit to its new amount, and the billing line underneath slides in from the direction you switched.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/pricing-toggle.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`
- Docs and live preview: https://hairlineui.com/ui/pricing-toggle
- Registry item (source): https://hairlineui.com/r/pricing-toggle.json

## Usage

```tsx
import { Price, PricingToggle } from "@/components/pricing-toggle";

const [billing, setBilling] = useState("monthly");

<PricingToggle value={billing} onValueChange={setBilling} />
<Price amount={billing === "yearly" ? 23 : 29} note={billing === "yearly" ? "$276 billed yearly" : "Billed monthly"} />
```

## In a pricing section

One toggle drives every plan column; each Price rolls on its own.

```tsx
"use client";
import { useState } from "react";
import { Price, PricingToggle } from "@/components/pricing-toggle";

const plans = [
  { name: "Starter", monthly: 12, yearly: 9 },
  { name: "Pro", monthly: 29, yearly: 23 },
  { name: "Team", monthly: 79, yearly: 63 },
];

export function Pricing() {
  const [billing, setBilling] = useState("monthly");
  const yearly = billing === "yearly";

  return (
    <section className="flex flex-col items-center gap-8">
      <PricingToggle value={billing} onValueChange={setBilling} />
      <div className="grid w-full gap-px overflow-hidden rounded-3xl border sm:grid-cols-3">
        {plans.map((plan) => (
          <div key={plan.name} className="bg-background p-6">
            <h3 className="text-sm font-medium">{plan.name}</h3>
            <Price
              amount={yearly ? plan.yearly : plan.monthly}
              direction={yearly ? 1 : -1}
              note={yearly ? `$${plan.yearly * 12} billed yearly` : "Billed monthly"}
            />
          </div>
        ))}
      </div>
    </section>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value / onValueChange` | `string / (value) => void` | – | The chosen billing period. |
| `options` | `{ value; label; badge? }[]` | `Monthly, Yearly “Save 20%”` | Any number of periods, e.g. add Lifetime. |
| `Price: amount / currency / period` | `number / string / string` | `— / "USD" / "/mo"` | The figure that rolls, its currency, and the period after it (hidden at 0). |
| `Price: locales` | `string \| string[]` | – | Format the price in this locale on the server and in the browser. Without it, a server render shows en-US and switches to the visitor’s locale after hydration ("$29" can become "US$29" in en-GB). |
| `Price: note / direction` | `string / 1 \| -1` | – | The line under the price, sliding in from the way the toggle moved. |
| `Price: numberClassName` | `string` | – | Size and weight of the figure. |

## States

- **monthly**: The thumb sits on Monthly; Yearly shows its badge in a soft tint as an incentive.
- **yearly**: The thumb slides and widens over Yearly and its badge, and the badge fills with your brand colour.
- **prices**: Each Price rolls to the new amount; the note ("$276 billed yearly") slides in from the toggle’s direction.

## What it handles

The billing switch is the one control every pricing page has, and usually the dullest. This one also rolls every price on the page to its new amount.

- **A thumb with a little give**: It slides and resizes to the chosen option, and the labels trade colour.
- **A badge that lights up**: “Save 20%” sits inside Yearly and fills with your brand colour when Yearly is chosen.
- **Every price rolls**: Each Price on the page rolls digit by digit to its new amount.
- **A billing note that follows**: The line under the price, such as “$276 billed yearly”, slides in from the direction you switched.
- **Any number of periods**: Pass your own options, for example add Lifetime.
- **A real radio group**: Arrow keys move between periods. Prices are real text for screen readers.

## Replaces

a billing switch, price formatting, a “Save 20%” badge, price change animation, a billing note

## Where it fits

- **Pricing pages**: A Monthly and Yearly switch that drives every plan on the page.
- **In-app upgrade screens**: Let people compare billing periods when they change plan.
- **Extra periods**: Add Quarterly or Lifetime beside Monthly and Yearly.
- **Checkout and upgrade dialogs**: A billing choice that updates the total beside it.

## Notes

- The toggle is a real radio group: arrow keys move between periods, and only the chosen one is in the tab order.
- Prices are real text for screen readers; the rolling digits are decoration on top.
- Installs Number roll alongside it.
- Price hydrates cleanly when server-rendered: without locales it formats in en-US until hydration, then in the visitor’s locale, swapped in place. The note is your own text, so if you write amounts in it, pass the same locales to Price to keep them alike.
- With reduced motion, the thumb jumps and prices change in place.

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