Docs
Installation
A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its button, badge dependencies and any missing npm packages, and installs them straight into your project.
npx shadcn add https://staaarter.com/r/monthly-yearly-toggle.jsonPrefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/pricing/pricing2.tsx instead.
Usage
The file also exports pricing2Demo, 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 { Pricing2, pricing2Demo } from "@/components/blocks/pricing/pricing2"; export default function Page() { return <Pricing2 {...pricing2Demo} />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | undefined | Optional section heading above the toggle and cards. |
| description | string | undefined | Optional supporting text under the heading. |
| tiers | PricingTier[] | none | The plan cards to render, left to right. |
| yearlyDiscountLabel | string | undefined | Badge text shown next to the toggle, e.g. "Save 20%". |
| className | string | none | Extra classes for the outer section element. |
Types
type PricingTier = { name: string; description: string; monthlyPrice: string; yearlyPrice: string; period: string; features: string[]; cta: { label: string; href?: string }; highlighted?: boolean; badgeLabel?: string; };
Behavior notes
- The toggle is real client-side state (useState): clicking it switches every tier's displayed price between monthlyPrice and yearlyPrice, both supplied per-tier via props, not hardcoded in the component.
- The toggle is a real role="switch" element with aria-checked reflecting the current billing period, plus visible "Monthly"/"Yearly" text labels that bold to indicate the active state.
- The yearlyDiscountLabel badge is always rendered when supplied but dims to 60% opacity while monthly is selected, then goes full opacity once yearly is selected, to draw attention to the switch.
- The highlighted tier gets a primary border, subtle shadow, and a slight scale-up on large screens, independent of which billing period is selected.
- All CTA buttons are inert placeholders with href="#", no real checkout or navigation wired up.
More Pricing Blocks
View all →Three Tier Cards
Classic three-column pricing cards with one plan visually highlighted as the recommended choice.
Single Plan Highlight
One centered, larger card for a single plan with a big price, full feature list, and a primary CTA.
Comparison Table
A full feature-matrix table comparing 3-4 plan tiers row by row, with a horizontal scroll fallback on mobile.
Enterprise Contact Card
A standard self-serve plan card next to a distinctly-styled Enterprise card with custom-quote messaging.
Pricing With Testimonial
Pricing cards paired with a single customer quote block for social proof, side by side on large screens.
Tabbed Audience Pricing
Pill tabs switch between separate plan sets for different audiences, e.g. individuals vs. teams.