Skip to content

Pricing Cards with Monthly/Yearly Toggle

Three-tier Tailwind CSS pricing section with an accessible billing switch and a highlighted plan.

Also known as: pricing table with toggle, monthly yearly pricing switch, saas pricing section, three tier pricing cards

Tailwind CSS Pricing Tables Responsive #cards #pricing #saas #toggle

Pricing Cards with Monthly/Yearly Toggle live demo

Open in new tab

Tailwind CSS code (HTML, JS)

A three-tier pricing section built with Tailwind CSS utilities, featuring a monthly/yearly billing switch, a highlighted "Most popular" plan and feature checklists. It is a ready-made pricing page block for SaaS products, apps and subscription services.

How it works

The root is section.tp-pricing. The header area contains the heading, a subtitle and the billing switch: a button.tp-switch with role="switch" and a sliding .tp-knob, flanked by "Monthly" and "Yearly" labels and a "Save 20%" pill. Below, a grid that becomes three columns at the md breakpoint holds three article cards: Starter, Pro and Business. The Pro card stands out with border-2 border-indigo-600, shadow-lg and an absolutely positioned badge. Each price is a span with data-monthly and data-yearly values, followed by a data-period span.

The script initializes every .tp-pricing on DOMContentLoaded. A click on .tp-switch flips aria-checked, swaps the track color between bg-slate-300 and bg-indigo-600, and moves the knob by swapping translate-x-1 and translate-x-6. It then rewrites every element with data-monthly using the matching attribute value, changes each data-period text to "/month, billed yearly" or "/month", and updates a status message. Without JavaScript the monthly prices remain visible and correct.

Customization

  • data-monthly and data-yearly on each price span: set your real prices; the script prefixes them with $.
  • The "Save 20%" pill next to #tp-yearly-label: update the percentage to match the difference between your prices.
  • bg-indigo-600 in the .tp-switch click handler in script.js and on the Pro card: replace with another Tailwind color such as bg-emerald-600 for a new accent.
  • md:grid-cols-3 on the cards grid: use lg:grid-cols-3 to keep cards stacked longer, or md:grid-cols-2 for two plans.
  • Move border-2 border-indigo-600, shadow-lg and the "Most popular" badge to another article to feature a different plan.
  • /month, billed yearly in script.js: change the period text, e.g. to show a yearly total.
  • max-w-5xl on the header and grid wrappers: widen or narrow the whole section.

Use cases

  • SaaS products: Starter, Pro and Business plans sit side by side with a highlighted Most popular tier
  • Subscription services: visitors switch between monthly and yearly billing and see prices update instantly
  • App landing pages: feature checklists under each plan make the differences easy to compare
  • Discount promotion: a Save 20% pill encourages visitors to choose yearly billing

Accessibility

The toggle is a real button with role="switch", aria-checked and aria-labelledby="tp-yearly-label", so screen readers announce "Yearly, switch, on/off". A sr-only paragraph with data-tp-status and aria-live="polite" announces "Showing yearly prices." or "Showing monthly prices." after each change. Checkmarks are aria-hidden, leaving clean feature text. The switch and every plan button use a visible focus-visible:ring-4 ring, and slate text on white keeps contrast high. The section is labelled by #tp-title.

Usage notes

Needs the Tailwind browser build (added automatically); there is no style.css. Several pricing sections can share a page because the script scopes all queries to each .tp-pricing, but give each copy unique label id values.

Pricing Cards with Monthly/Yearly Toggle at a glance

Framework
Tailwind CSS
Code
HTML, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile
Category
Pricing Tables
License
Free for personal and commercial use

Questions about this template

Can I use the Pricing Cards with Monthly/Yearly Toggle code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Pricing Cards with Monthly/Yearly Toggle – free Tailwind CSS pricing table template
Pricing Cards with Monthly/Yearly Toggle · free Tailwind CSS pricing table template

More Pricing Tables

Pricing Cards with Billing Toggle – free Bootstrap 5 pricing table template

Pricing Cards with Billing Toggle

Bootstrap 5 pricing cards with a Monthly / Annual segmented switch that updates prices, savings and yearly totals, plus a highlighted featured plan.

Pricing Table with Feature Tooltips – free Bootstrap 5 pricing table template

Pricing Table with Feature Tooltips

Bootstrap 5 plan comparison table with a highlighted popular plan and info tooltips that explain every feature on hover or keyboard focus.

Pricing with Team Size Range – free Bootstrap 6 pricing table template

Pricing with Team Size Range

Bootstrap 6 per-seat pricing card with a Range slider for team size, volume tiers, a monthly/annual toggle and a live total price.

Dark Pricing Section – free Bootstrap 6 pricing table template

Dark Pricing Section

Dark Bootstrap 6 pricing section with three glass cards, a gradient-bordered recommended plan, a currency Menu and an FAQ link that opens a Drawer with an accordion.

Pricing Comparison Table – free Bootstrap 6 pricing table template

Pricing Comparison Table

Bootstrap 6 feature comparison table across four plans with check icons, a highlighted Pro column, tooltips, a sticky feature column and an Only differences filter.

Pricing Table with Highlighted Plan – free Bootstrap 6 pricing table template

Pricing Table with Highlighted Plan

Bootstrap 6 pricing cards with a raised dark green Most popular plan, gold accents and a team-size Range slider that recalculates every plan's monthly total.