Pricing Toggle
Monthly/yearly pricing switch with sliding pill.
<div class="inline-flex items-center rounded-full border border-slate-200 bg-slate-100 p-1"> <button class="px-5 py-2 rounded-full text-sm font-bold bg-white shadow text-slate-900">Monthly</button> <button class="px-5 py-2 rounded-full text-sm font-bold text-slate-500 hover:text-slate-700 transition-colors">Yearly <span class="text-emerald-600 text-xs">-20%</span></button> </div>
Free to use in personal and commercial projects. No attribution required.
Variants
Same component, different looks. Preview each one live and copy the code you like.
Yearly active
Show the yearly state as default when annual billing is your main push.
Three options
Use three options when you also sell a one-time lifetime plan.
Dark
The dark toggle matches dark pricing pages and dashboards.
About this pricing toggle
Nearly every SaaS pricing page has this exact component: a monthly/yearly toggle that switches prices with one click. It is a small element with an outsized job, because the yearly option with its discount badge is how SaaS companies nudge visitors toward annual plans.
This tailwind pricing toggle uses the sliding-pill pattern. The active option gets a white background and shadow, sitting inside a gray track. The "-20%" badge on the yearly option is the classic nudge. Wire the buttons to your pricing logic with a few lines of JavaScript that swap the displayed prices.
Accessibility note: use real buttons (not divs) and aria-pressed so screen readers announce the selected billing period. That is already handled in this snippet.
Pricing pages have a comparison problem: show monthly and yearly side by side and the page gets cluttered; split them across pages and visitors never compare. The toggle solves it with one control that flips every price on the page at once. It also does quiet sales work: pairing the yearly option with a visible discount reframes annual billing as the clever choice, which is why this exact component appears on nearly every SaaS pricing page.
The code is a sliding-pill pattern: an inline-flex rounded-full border bg-slate-100 p-1 track holding two buttons. The active option gets bg-white shadow text-slate-900, which reads as a physical pill sitting in the track; the inactive one is text-slate-500 with a hover darkening. The -20% badge in text-emerald-600 text-xs is the nudge. A few lines of JavaScript toggle the active classes and rewrite the price text nodes across the page.
Make the badge specific: -20% beats a vague Save, and -17% (the real math on many plans) beats a rounded lie. Add microcopy under the price like billed annually so the deal is unambiguous. If you want the sliding animation, use one absolutely positioned pill that moves with translate-x to the active button instead of swapping backgrounds; measure with offsetLeft for accuracy.
The mistake that destroys trust is showing the yearly price as a per-month figure ($16/mo, billed annually) without showing the actual charge anywhere near the toggle. Visitors do the math at checkout, see $192, and feel tricked. Always pair the per-month figure with the total billed amount in the same view; the toggle should clarify the deal, not hide it.
Where to use it
- ✓ SaaS pricing pages
- ✓ Subscription plan selectors
- ✓ Billing settings
- ✓ Feature comparison tables
Customization tips
Adjust the discount percentage to match your annual deal. For a more animated feel, add transition-all and move a single pill with translate-x instead of swapping backgrounds. Keep the two options short: "Monthly" and "Yearly" or "Annual".
Design notes
When to use
Use it on SaaS pricing pages and plan selectors where the yearly discount nudges visitors toward annual billing. The sliding pill with a minus 20 percent badge is the pattern buyers already understand. Keep the two options short: Monthly and Yearly.
What to avoid
Do not default to yearly without making the choice obvious; users who miss it feel tricked at checkout. Do not let the displayed prices fall out of sync with the toggle, wrong prices destroy trust instantly.
Accessibility
Use real buttons with aria-pressed so screen readers announce the selected billing period. Ensure the whole toggle is keyboard operable with a visible focus state.
Frequently asked questions
How do I wire a pricing toggle to update prices?
Add a click handler on each button that toggles the active styles and updates price elements on the page. Store monthly and yearly prices in data attributes and swap the text content.
Should the yearly option show a discount badge?
Yes, if you offer annual billing at a lower effective monthly rate. The badge makes the savings concrete and lifts yearly conversions.
Monthly/yearly toggle vs separate pricing tables?
A toggle keeps one clean table and lets visitors compare instantly. Separate tables work when monthly and yearly plans have genuinely different features.
How do I animate the pricing toggle knob sliding between monthly and yearly?
Place the knob as an absolutely positioned pill inside the track and move it with translate-x, toggling the class in JavaScript. A transition on transform gives the smooth slide. Size the knob to exactly half the track width so it lands cleanly on either side.
How do I remember the pricing toggle choice on page reload?
Save the selected billing period to localStorage whenever the toggle changes, then read it on page load and set the toggle and prices before first paint. This avoids a flash of the wrong prices. Default to monthly when nothing is stored.
How do I show a smooth price change when the toggle flips?
Store both prices in data-monthly and data-yearly attributes on each price element. On toggle, fade the number out, swap the textContent, then fade back in, or run a quick count animation between the two values. Update any per-month or per-year suffix labels at the same time.