- Published on
6 Ideas To Help You Make A Pricing Table With JS Toggle With Tailwind CSS Like A Pro

- What is Tailwind CSS?
- The description of Pricing Table with JS Toggle ui component
- Why use Tailwind CSS to build a Pricing Table with JS Toggle ui component?
- The preview of Pricing Table with JS Toggle ui component
- The source code of Pricing Table with JS Toggle ui component
- How to build a Pricing Table with JS Toggle with Tailwind CSS?
- Install tailwind css of verion 1.4.6
- All the unility class needed to build a Pricing Table with JS Toggle component
- 54 steps to build a Pricing Table with JS Toggle component with Tailwind CSS
- Conclusion
What is Tailwind CSS?
Tailwind CSS is a utility-first CSS framework that focuses on creating personalized user interfaces quickly. It can gives you all the building blocks you are able to create personalized designs without having to fight to override irritating opinionated styles. Also, Tailwind CSS is a highly configurable, low-level CSS framework.
The description of Pricing Table with JS Toggle ui component
Why use Tailwind CSS to build a Pricing Table with JS Toggle ui component?
- It can make the building process of Pricing Table with JS Toggle ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Pricing Table with JS Toggle component file.
The preview of Pricing Table with JS Toggle ui component
Free download of the Pricing Table with JS Toggle's source code
The source code of Pricing Table with JS Toggle ui component
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Work+Sans:[email protected];700&display=swap" rel="stylesheet">
<title>Tailwind CSS Pricing Table with Toggle</title>
<style>
@media (min-width: 640px) {
.sm\:bg-svg-bottom {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='353' height='304'%3E%3Cg fill='none' fill-rule='evenodd' stroke='%23D0D5F6' stroke-width='2'%3E%3Cpath d='M180.29 759c102.087-21.62 155.232-61.312 159.437-119.074 6.307-86.643-231.598-17.186-136.358-198 95.241-180.813 181.318-185.29 136.358-298C294.767 31.216 174.04-27.954 33.79 16.8c-93.501 29.836-144.652 140.545-153.453 332.126'/%3E%3Cpath d='M138.3 759c80.083-18.988 121.774-53.846 125.072-104.575 4.948-76.093-181.679-15.094-106.966-173.89C231.118 321.738 298.64 317.808 263.372 218.82c-35.269-98.986-129.974-150.95-239.995-111.646C-49.97 133.378-90.096 230.605-97 398.859'/%3E%3Cpath d='M102.065 761c60.604-16.56 92.153-46.963 94.65-91.208 3.743-66.367-137.488-13.165-80.949-151.664 56.54-138.5 107.638-141.927 80.948-228.261-26.69-86.335-98.359-131.656-181.618-97.376C-40.41 215.345-70.775 300.145-76 446.892'/%3E%3C/g%3E%3C/svg%3E");
}
}
.toggle_dot {
top: -.25rem;
transition: all 0.3s ease-in-out;
}
input:checked~.toggle_dot {
transform: translateX(100%);
background-color: #0082c8;
}
.bg-gradient {
background: #667db6;
/* fallback for old browsers */
background: -webkit-linear-gradient(to right, #667db6, #0082c8, #0082c8, #667db6);
/* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #667db6, #0082c8, #0082c8, #667db6);
/* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
.bg-gradient-base {
background-color: #0082c8;
}
.font-work-sans {
font-family: 'Work Sans', sans-serif;
}
</style>
</head>
<body class="text-gray-900 font-work-sans h-screen bg-no-repeat bg-left-bottom sm:bg-svg-bottom">
<svg class="absolute top-0 right-0 h-full" xmlns="http://www.w3.org/2000/svg" width"375" height"658">
<g fill="none" fill-rule="evenodd" stroke="#D0D5F6" stroke-width="2">
<path d="M172.71-101C70.623-79.38 17.478-39.688 13.273 18.074c-6.307 86.643 231.598 17.186 136.358 198-95.241 180.813-181.318 185.29-136.358 298C58.233 626.784 178.96 685.954 319.21 641.2c93.501-29.836 144.652-140.545 153.453-332.126" />
<path d="M214.7-101C134.617-82.012 92.926-47.154 89.628 3.575c-4.948 76.093 181.679 15.094 106.966 173.89C121.882 336.262 54.36 340.192 89.628 439.18c35.269 98.986 129.974 150.95 239.995 111.646C402.97 524.622 443.096 427.395 450 259.141" />
<path d="M250.935-103c-60.604 16.56-92.153 46.963-94.65 91.208-3.743 66.367 137.488 13.165 80.949 151.664-56.54 138.5-107.638 141.927-80.948 228.261 26.69 86.335 98.359 131.656 181.618 97.376C393.41 442.655 423.775 357.855 429 211.108" />
</g>
</svg>
<h1 class="text-center font-bold text-5xl mt-8 tracking-wide relative">Our Pricing</h1>
<div class="flex flex-row justify-center my-4 text-sm tracking-tight font-medium text-gray-700">
<p class="mx-3">Annually</p>
<!-- Toggle Button -->
<label for="toggle" class="flex items-center cursor-pointer">
<!-- toggle -->
<div class="relative">
<!-- hidden input -->
<input id="toggle" type="checkbox" class="hidden" onclick="myFunction()" />
<!-- line -->
<div class="w-10 h-3 bg-gray-400 rounded-full shadow-inner"></div>
<!-- dot -->
<div class="toggle_dot absolute w-5 h-5 bg-white rounded-full shadow inset-y-0 left-0"></div>
</div>
</label>
<p class="mx-3">Monthly</p>
</div>
<div class="flex flex-col md:flex-row md:transform md:scale-75 lg:scale-100 justify-center">
<div class="border rounded-lg md:rounded-r-none text-center p-5 mx-auto md:mx-0 my-2 md:my-6 bg-gray-100 font-medium z-10 shadow-lg">
<div class="">Basic</div>
<div id="month" class="font-bold text-6xl month hidden">$19.99</div>
<div id="annual" class="font-bold text-6xl annual">$199.99</div>
<hr>
<div class="text-sm my-3">500 GB Storage</div>
<hr>
<div class="text-sm my-3">2 Users Allowed</div>
<hr>
<div class="text-sm my-3">Send up to 3 GB</div>
<hr>
<a href="#" target="_blank">
<div class="bg-gradient-base border border-blue-600 hover:bg-white text-white hover:text-blue-600 font-bold uppercase text-xs mt-5 py-2 px-4 rounded cursor-pointer">Learn More</div>
</a>
</div>
<div class="border-transparent rounded-lg text-center p-5 mx-auto md:mx-0 my-2 bg-gradient text-white font-medium z-10 shadow-lg">
<div class="py-4">Professional
<div id="month" class="font-bold text-6xl month hidden">$24.99</div>
<div id="annual" class="font-bold text-6xl annual">$249.99</div>
<hr>
<div class="text-sm my-3">1 TB Storage</div>
<hr>
<div class="text-sm my-3">5 Users Allowed</div>
<hr>
<div class="text-sm my-3">Send up to 10 GB</div>
<hr>
<a href="#" target="_blank">
<div class="bg-white border border-white hover:bg-transparent text-blue-600 hover:text-white font-bold uppercase text-xs mt-5 py-2 mpx-4 rounded cursor-pointer">Learn More</div>
</a>
</div>
</div>
<div class="border rounded-lg md:rounded-l-none text-center p-5 mx-auto md:mx-0 my-2 md:my-6 bg-gray-100 font-medium z-10 shadow-lg">
<div class="">Master</div>
<div id="month" class="font-bold text-6xl month hidden">$39.99</div>
<div id="annual" class="font-bold text-6xl annual">$399.99</div>
<hr>
<div class="text-sm my-3">2 TB Storage</div>
<hr>
<div class="text-sm my-3">10 Users Allowed</div>
<hr>
<div class="text-sm my-3">Send up to 20 GB</div>
<hr>
<a href="#" target="_blank">
<div class="bg-gradient-base border border-blue-600 hover:bg-transparent text-white hover:text-blue-600 font-bold uppercase text-xs mt-5 py-2 px-4 rounded cursor-pointer">Learn More</div>
</a>
</div>
</div>
<!--JS for toggle-->
<script>
function myFunction() {
var x = document.querySelectorAll('.annual');
var y = document.querySelectorAll('.month');
for (var i = 0; i < x.length; i++) {
if (document.getElementById("toggle").checked == true) {
x[i].classList.add('hidden');
y[i].classList.remove('hidden');
} else {
x[i].classList.remove('hidden');
y[i].classList.add('hidden');
}
}
}
</script>
</body>
</html>
How to build a Pricing Table with JS Toggle with Tailwind CSS?
Install tailwind css of verion 1.4.6
Use the link
html tag to import the stylesheet of Tailwind CSS of the version 1.4.6
<link href=https://unpkg.com/[email protected]/dist/tailwind.min.css rel="stylesheet">
All the unility class needed to build a Pricing Table with JS Toggle component
text-gray-900
h-screen
bg-no-repeat
bg-left-bottom
sm:bg-svg-bottom
absolute
top-0
right-0
h-full
text-center
text-5xl
mt-8
relative
flex
flex-row
my-4
text-sm
text-gray-700
mx-3
hidden
w-10
h-3
bg-gray-400
w-5
h-5
bg-white
left-0
flex-col
md:flex-row
p-5
mx-auto
md:mx-0
my-2
md:my-6
bg-gray-100
z-10
text-6xl
my-3
bg-gradient-base
border-blue-600
hover:bg-white
text-white
hover:text-blue-600
text-xs
mt-5
py-2
px-4
border-transparent
bg-gradient
py-4
border-white
hover:bg-transparent
text-blue-600
hover:text-white
54 steps to build a Pricing Table with JS Toggle component with Tailwind CSS
Control the text color of an element to gray-900 using the
text-gray-900
utilities.Use
h-screen
to make an element span the entire height of the viewport.Control the background color of an element to no-repeat using the
bg-no-repeat
utilities.Control the background color of an element to left-bottom using the
bg-left-bottom
utilities.Control the background color of an element to svg-bottom using the
sm:bg-svg-bottom
utilities at only small screen sizes.Use
absolute
to position an element outside of the normal flow of the document, causing neighboring elements to act as if the element doesn’t exist.Use the
top-0
utilities to set the top position of a positioned element to 0rem.Use the
right-0
utilities to set the right position of a positioned element to 0rem.Use
h-full
to set an element’s height to 100% of its parent, as long as the parent has a defined height.Control the text color of an element to center using the
text-center
utilities.Control the text color of an element to 5xl using the
text-5xl
utilities.Control the margin on top side of an element to 2rem using the
mt-8
utilities.Use
relative
to position an element according to the normal flow of the document.Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.Control the vertical margin of an element to 1rem using the
my-4
utilities.Control the text color of an element to sm using the
text-sm
utilities.Control the text color of an element to gray-700 using the
text-gray-700
utilities.Control the horizontal margin of an element to 0.75rem using the
mx-3
utilities.Use
hidden
to set an element to display: none and remove it from the page layout.Use
w-10
to set an element to a fixed width(2.5rem).Use
h-3
to set an element to a fixed height(0.75rem).Control the background color of an element to gray-400 using the
bg-gray-400
utilities.Use
w-5
to set an element to a fixed width(1.25rem).Use
h-5
to set an element to a fixed height(1.25rem).Control the background color of an element to white using the
bg-white
utilities.Use the
left-0
utilities to set the left position of a positioned element to 0rem.Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container at only medium screen sizes.Control the padding on all sides of an element to 1.25rem using the
p-5
utilities.Control the horizontal margin of an element to auto using the
mx-auto
utilities.Control the horizontal margin of an element to 0rem at only medium screen sizes using the
md:mx-0
utilities.Control the vertical margin of an element to 0.5rem using the
my-2
utilities.Control the vertical margin of an element to 1.5rem at only medium screen sizes using the
md:my-6
utilities.Control the background color of an element to gray-100 using the
bg-gray-100
utilities.Control the stack order (or three-dimensional positioning) of an element to 10 in Tailwind, regardless of order it has been displayed, using the
z-10
utilities.Control the text color of an element to 6xl using the
text-6xl
utilities.Control the vertical margin of an element to 0.75rem using the
my-3
utilities.Control the background color of an element to gradient-base using the
bg-gradient-base
utilities.Control the border color of an element to blue-600 using the
border-blue-600
utilities.Control the background color of an element to white using the
hover:bg-white
utilities on hover.Control the text color of an element to white using the
text-white
utilities.Control the text color of an element to blue-600 on hover using the
hover:text-blue-600
utilities.Control the text color of an element to xs using the
text-xs
utilities.Control the margin on top side of an element to 1.25rem using the
mt-5
utilities.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.Control the horizontal padding of an element to 1rem using the
px-4
utilities.Control the border color of an element to transparent using the
border-transparent
utilities.Control the background color of an element to gradient using the
bg-gradient
utilities.Control the vertical padding of an element to 1rem using the
py-4
utilities.Control the border color of an element to white using the
border-white
utilities.Control the background color of an element to transparent using the
hover:bg-transparent
utilities on hover.Control the text color of an element to blue-600 using the
text-blue-600
utilities.Control the text color of an element to white on hover using the
hover:text-white
utilities.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to build a Pricing Table with JS Toggle components, learn and follow along to implement your own components.