Building a Flexible Pricing Section with Toggle Switch for Monthly and Yearly Plans

Creating a flexible pricing section is essential for many websites, especially SaaS and subscription services. A toggle switch that allows users to switch between monthly and yearly plans enhances user experience and provides clear pricing options. This guide will walk you through building a responsive and interactive pricing section using Gutenberg blocks.

Designing the Pricing Section

Start by planning the layout. A common approach is to display the toggle switch at the top, followed by pricing cards for each plan. Use columns to organize the content and ensure responsiveness across devices.

Creating the Toggle Switch

Use a button or a custom toggle switch to allow users to select between monthly and yearly billing. You can implement this with simple HTML and CSS within a Custom HTML block, or use a plugin for more advanced features.

Here’s a basic example of a toggle switch:

<div class="toggle-switch">
  <input type="checkbox" id="billing-toggle">
  <label for="billing-toggle">Monthly / Yearly</label>
</div>

Style the toggle with CSS to make it visually appealing and intuitive. When toggled, it should update the pricing displayed on the cards dynamically, which can be achieved with JavaScript.

Building the Pricing Cards

Use columns to create individual pricing cards. Each card should include the plan name, features, and price. Prepare two sets of prices: one for monthly and one for yearly billing.

Basic Plan

Ideal for individuals starting out.

$10/mo

Pro Plan

Perfect for growing businesses.

$30/mo

Enterprise Plan

Designed for large organizations.

$100/mo

Implement JavaScript to listen for toggle switch changes and update the prices accordingly. This provides a seamless experience for users switching between plans.

Final Tips

Ensure the pricing section is mobile-friendly and accessible. Use clear labels and sufficient contrast. Regularly test the toggle functionality to maintain a smooth user experience.