Pricing Table with CSS Switch Toggle

Pricing Table with CSS Switch Toggle
Code Snippet:Pricing table with toggle button
Author: Alina N.
Published: January 20, 2024
Last Updated: January 22, 2024
Downloads: 1,594
License: MIT
Edit Code online: View on CodePen
Read More

This code creates a pricing table with an interactive toggle switch in HTML, CSS, and JavaScript. The switch allows users to switch between annual and monthly pricing plans easily. It enables easy comparison of subscription costs and highlights the selected option.

You can use this code on your website’s pricing page to enhance user experience. It helps customers quickly toggle between annual and monthly pricing, making it easier for them to choose a subscription plan. This feature can boost conversions and simplify the decision-making process for your potential clients.

How to Create Pricing Table With CSS Switch Toggle

1. Start by creating the HTML structure for your pricing table. You can copy and paste the following HTML code into your project.

 <div class="container">
    <div class="top">
      <h1>Plans & Pricing</h1>
      <div class="toggle-btn">
        <span style="margin: 0.8em;">Annually</span>
        <label class="switch">
          <input type="checkbox" id="checbox" onclick="check()" ; />
          <span class="slider round"></span>
        </label>
        <span style="margin: 0.8em;">Monthly</span></div>
    </div>

    <div class="package-container">
      <div class="packages">
        <h1>Basic</h1>
        <h2 class="text1">&dollar;9.99</h2>
        <h2 class="text2">&dollar;119.99</h2>
        <ul class="list">
          <li class="first">2000 Subscribers</li>
          <li>12,000 Emails/month</li>
          <li>Multi-User Accounts</li>
          <li>Email Support</li>
        </ul>
        <a href="#" class="button button1">Start Now</a>
      </div>
      <div class="packages">
        <h1>Professional</h1>
        <h2 class="text1">&dollar;19.99</h2>
        <h2 class="text2">&dollar;239.99</h2>
        <ul class="list">
          <li class="first">Basic +</li>
          <li>Landing Pages</li>
          <li>Pop-up Forms</li>
          <li>Premium Support</li>
        </ul>
        <a href="#" class="button button2">Start Now</a>
      </div>
      <div class="packages">
        <h1>Master</h1>
        <h2 class="text1">&dollar;29.99</h2>
        <h2 class="text2">&dollar;359.99</h2>
        <ul class="list">
          <li class="first">Professional +</li>
          <li>Marketing Automation</li>
          <li>Instagram Ads</li>
          <li>Facebook Ads</li>
        </ul>
        <a href="#" class="button button3">Start Now</a>
      </div>
    </div>
  </div>

2. Next, we’ll apply styles to our pricing table using CSS. You can customize the design to match your website’s theme by modifying the CSS code.

@import url("https://fonts.googleapis.com/css2?family=Play:wght@400;700&display=swap");

body {
  background-color: #f4f4f4;

  font-family: "Play", sans-serif;
}

.container {
  width: 100%;
}

.packages {
  padding: 20px 10px;
  margin: 20px;
  width: 300px;
  padding-bottom: 1.5em;
  height: 100%;
  background-color: #1e2321;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  border-radius: 20px;
  box-shadow: 0 19px 38px rgba(30, 35, 33, 1), 0 15px 12px rgba(30, 35, 33, 0.2);
  flex-wrap: wrap;
  color: #f4f4f4;
}

h1,
h2 {
  font-size: 2.2em;
}

.list li {
  font-size: 20px;
  list-style: none;
  border-bottom: 1px solid #f4f4f4;
  padding-inline-start: 0;
  border-width: 1px;
  padding: 10px;
}

.first {
  margin-top: 40px;
  border-top: 1px solid #f4f4f4;
}

.list {
  width: 80%;
}

ol,
ul {
  padding: 0;
}

.top {
  display: flex;
  flex-direction: column;
  align-items: center;
}

input,
label {
  display: inline-block;
  vertical-align: middle;
  margin: 10px 0;
}

.button {
  padding: 10px 30px;
  text-decoration: none;
  font-size: 1.4em;
  margin: 15px 15px;
  border-radius: 50px;
  color: #f4f4f4;
  transition: all 0.3s ease 0s;
}

.button:hover {
  transform: scale(1.2);
}

.button1 {
  background-color: #00cc99;
  box-shadow: 0 0 10px 0 #00cc99 inset, 0 0 20px 2px #00cc99;
}

.button2 {
  background-color: #ff007c;
  box-shadow: 0 0 10px 0 #ff007c inset, 0 0 20px 2px #ff007c;
}

.button3 {
  background-color: #ffae42;
  box-shadow: 0 0 10px 0 #ffae42 inset, 0 0 20px 2px #ffae42;
}

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #1e2321;
  -webkit-transition: 0.4s;

  box-shadow: 2px 6px 25px #1e2321;
  transform: translate(0px, 0px);
  transition: 0.6s ease transform, 0.6s box-shadow;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: 0.4s;
  transition: 0.4s;
}

input:checked + .slider {
  background-color: #50bfe6;
}

input:focus + .slider {
  box-shadow: 0 0 1px #50bfe6;
}

input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

.package-container {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

3. To make the switch toggle work, we’ll add JavaScript functionality. This script enables the dynamic switching between annual and monthly prices. Insert the JavaScript code just before the closing </body> tag in your HTML file.

function check() {
  var checkBox = document.getElementById("checbox");
  var text1 = document.getElementsByClassName("text1");
  var text2 = document.getElementsByClassName("text2");

  for (var i = 0; i < text1.length; i++) {
    if (checkBox.checked == true) {
      text1[i].style.display = "block";
      text2[i].style.display = "none";
    } else if (checkBox.checked == false) {
      text1[i].style.display = "none";
      text2[i].style.display = "block";
    }
  }
}
check();

That’s all! Hopefully, you’ve successfully created a Pricing Table with Switch Toggle for your website. If you have any questions or suggestions, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X