opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Pricing
  4. Toggle Pricing Cards
Back to Pricing

Components / Pricing

Toggle Pricing Cards

Free Pricing React component — TogglePricingCards. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Monthly and yearly billing toggle that updates three plan cards side by side — price and feature checklist included. SaaS pricing page, one paste away.

Preview

MonthlyYearly-20%

Starter

$0/mo

  • 10 components
  • Community support
Popular

Pro

$29/mo

  • 50+ components
  • Priority support
  • Custom themes

Team

$99/mo

  • Unlimited
  • SSO
  • Dedicated support

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/pricing/toggle-pricing-cards.tsx in your project.

  4. 4

    Import and render:

    Example

    import { TogglePricingCards } from "@/components/pricing/toggle-pricing-cards";

    <TogglePricingCards />

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/pricing/toggle-pricing-cards.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
"use client";
 
import { forwardRef, useState, type ComponentPropsWithoutRef } from "react";
 
import { cn } from "@/lib/cn";
 
import { Check } from "lucide-react";
 
/**
* Toggle pricing cards built with Next.js, React,
* TypeScript, and Tailwind CSS.
*
* Replace the plans, pricing, and discount values
* with your own data.
*
* Need icons? Visit nexticons.in for free copy-paste icons.
*/
export type PricingPlan = {
name: string;
price: number;
yearlyPrice?: number;
popular?: boolean;
features: string[];
};
 
export type TogglePricingCardsProps = Readonly<
{
defaultYearly?: boolean;
 
monthlyLabel?: string;
yearlyLabel?: string;
 
discountLabel?: string;
 
plans?: PricingPlan[];
} & ComponentPropsWithoutRef<"div">
>;
 
// Production-ready Toggle Pricing Cards component — styled with Tailwind CSS.
export const TogglePricingCards = forwardRef<
HTMLDivElement,
TogglePricingCardsProps
>(
(
{
className,
 
defaultYearly = false,
 
monthlyLabel = "Monthly",
yearlyLabel = "Yearly",
 
discountLabel = "-20%",
 
plans = [
{
name: "Starter",
price: 0,
yearlyPrice: 0,
features: ["10 components", "Community support"],
},
{
name: "Pro",
price: 29,
yearlyPrice: 24,
popular: true,
features: ["50+ components", "Priority support", "Custom themes"],
},
{
name: "Team",
price: 99,
yearlyPrice: 79,
features: ["Unlimited", "SSO", "Dedicated support"],
},
],
 
...props
},
ref,
) => {
const [yearly, setYearly] = useState(defaultYearly);
 
return (
<div
ref={ref}
data-slot="toggle-pricing-cards"
className={cn("w-96 font-sans", className)}
{...props}
>
{/* Billing Toggle */}
<div
data-slot="toggle-pricing-cards-switch"
className="mb-4 flex items-center justify-center gap-3"
>
<span
className={cn(
"text-xs font-medium",
!yearly ? "text-neutral-900" : "text-neutral-400",
)}
>
{monthlyLabel}
</span>
 
<button
type="button"
aria-label="Toggle billing period"
onClick={() => setYearly((prev) => !prev)}
className={cn(
"relative h-6 w-11 cursor-pointer rounded-full transition-colors",
yearly ? "bg-neutral-800" : "bg-neutral-200",
)}
>
<div
className={cn(
"absolute top-0.5 h-5 w-5 rounded-full bg-white shadow-sm transition-transform",
yearly ? "translate-x-5.5" : "translate-x-0.5",
)}
/>
</button>
 
<span
className={cn(
"text-xs font-medium",
yearly ? "text-neutral-900" : "text-neutral-400",
)}
>
{yearlyLabel}
 
<span className="ml-1 text-[10px] font-semibold text-emerald-600">
{discountLabel}
</span>
</span>
</div>
 
{/* Plans */}
<div data-slot="toggle-pricing-cards-plans" className="flex gap-2">
{plans.map((plan) => {
const price = yearly
? (plan.yearlyPrice ?? plan.price)
: plan.price;
 
return (
<div
key={plan.name}
data-slot="toggle-pricing-cards-plan"
className={cn(
"flex-1 rounded-xl border p-3 transition-all",
plan.popular
? "border-neutral-900 bg-neutral-900 text-white shadow-lg"
: "border-neutral-100 bg-white",
)}
>
{plan.popular && (
<span className="font-mono text-[8px] tracking-wider text-teal-300 uppercase">
Popular
</span>
)}
 
<p
className={cn(
"mt-1 text-[10px] font-medium",
plan.popular ? "text-neutral-400" : "text-neutral-500",
)}
>
{plan.name}
</p>
 
<p className="mt-1 text-lg font-light tracking-tight">
${price}
<span
className={cn(
"text-[10px]",
plan.popular ? "text-neutral-500" : "text-neutral-400",
)}
>
/mo
</span>
</p>
 
<ul className="mt-2 space-y-1">
{plan.features.map((feature) => (
<li
key={feature}
className={cn(
"flex items-center gap-1 text-[9px]",
plan.popular ? "text-neutral-400" : "text-neutral-500",
)}
>
<Check
size={8}
className={
plan.popular ? "text-teal-400" : "text-emerald-500"
}
/>
 
{feature}
</li>
))}
</ul>
</div>
);
})}
</div>
</div>
);
},
);
 
TogglePricingCards.displayName = "TogglePricingCards";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/pricing/toggle-pricing-cards.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.