Staaarter

Billing Yearly Savings Toggle

A compact pricing toggle for a single plan. Switching between monthly and yearly recalculates the displayed price to the effective monthly rate, and a savings line shows the total amount and percentage saved by choosing annual billing. A 'Best value' badge appears next to the plan name whenever yearly is active and there's a real discount to show.

By Staaarter Team
Billing
Updated July 23, 2026
Docs
Live preview

Docs

Installation

A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its badge, button dependencies and any missing npm packages, and installs them straight into your project.

npx shadcn add https://staaarter.com/r/billing-yearly-savings-toggle.json

Prefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/billing/billing150.tsx instead.

Usage

The file also exports billing150Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.

import { Billing150, billing150Demo } from "@/components/blocks/billing/billing150";

export default function Page() {
  return <Billing150 {...billing150Demo} />;
}

Props

PropTypeDefaultDescription
headingstringnoneOptional heading above the toggle.
descriptionstringnoneOptional supporting text under the heading.
planNamestring"Pro"Plan name shown above the price.
monthlyPricenumbernonePrice per month when billed monthly.
annualPricenumbernoneTotal price for the year when billed annually, not a monthly figure.
currencySymbolstring"$"Symbol used in every formatted amount.
defaultYearlybooleantrueWhether the yearly option is active on first render.
ctaLabelstring"Continue"Label on the bottom button.
ctaHrefstring"#"Destination for the bottom button.
classNamestringnoneExtra classes for the outer container.

Behavior notes

  • isYearly is local state; toggling it swaps the displayed price between monthlyPrice and annualPrice divided by 12, formatted to the nearest cent.
  • Total savings is computed as (monthlyPrice * 12) minus annualPrice, and the percentage is that savings divided by the monthly total, rounded to the nearest whole percent.
  • The savings line and the 'Best value' badge are both skipped when the computed savings is zero or negative, so passing an annualPrice that isn't actually cheaper hides them rather than showing a misleading number.
  • The savings line stays in the layout at all times to avoid a height jump when toggling; it's just faded to opacity-0 while monthly is active.
  • The bottom button is a next/link styled as a button, not a form submit, so wiring it to checkout or an upgrade flow is up to the caller.

Frequently asked questions