- Published on
Here Are 6 Ways To Create A Call To Action With Tailwind CSS

- What is Tailwind CSS?
- The description of Call To Action ui component
- Why use Tailwind CSS to create a Call To Action ui component?
- The preview of Call To Action ui component
- The source code of Call To Action ui component
- How to create a Call To Action with Tailwind CSS?
- Install tailwind css of verion 2.2.19
- All the unility class needed to create a Call To Action component
- 45 steps to create a Call To Action 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 Call To Action ui component
E-commerce call to action section, find more on tailus.io/blocks/call-to-action
Why use Tailwind CSS to create a Call To Action ui component?
- It can make the building process of Call To Action ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Call To Action component file.
The preview of Call To Action ui component
Free download of the Call To Action's source code
The source code of Call To Action ui component
<div class="py-16 bg-white">
<div class="container m-auto px-6 space-y-8 text-gray-500 md:px-12 lg:px-20">
<div class="justify-center text-center gap-6 md:text-left md:flex lg:items-center lg:gap-16">
<div class="order-last mb-6 space-y-6 md:mb-0 md:w-6/12 lg:w-6/12">
<h1 class="text-4xl text-gray-700 font-bold md:text-5xl">Buy now and benefit up to <span class="text-blue-500">30% off</span></h1>
<p class="text-lg">Be part of millions people around the world using tailus in modern User Interfaces.</p>
<div class="flex flex-row-reverse flex-wrap justify-center gap-4 md:gap-6 md:justify-end">
<button type="button" title="Start buying" class="w-full py-3 px-6 text-center rounded-xl transition bg-gray-700 shadow-xl hover:bg-gray-600 active:bg-gray-700 focus:bg-gray-600 sm:w-max">
<span class="block text-white font-semibold">
Start buying
</span>
</button>
<button type="button" title="more about" class="w-full order-first py-3 px-6 text-center rounded-xl bg-gray-100 transition hover:bg-gray-200 active:bg-gray-300 focus:bg-gray-200 sm:w-max">
<span class="block text-gray-600 font-semibold">
More about
</span>
</button>
</div>
</div>
<div class="grid grid-cols-5 grid-rows-4 gap-4 md:w-5/12 lg:w-6/12">
<div class="col-span-2 row-span-4">
<img src="https://tailus.io/sources/blocks/ecommerce-site/preview/images/products/kushagra.webp" class="rounded-full" width="640" height="960" alt="shoes" loading="lazy">
</div>
<div class="col-span-2 row-span-2">
<img src="https://tailus.io/sources/blocks/ecommerce-site/preview/images/products/iman.webp" class="w-full h-full object-cover object-top rounded-xl" width="640" height="640" alt="shoe" loading="lazy">
</div>
<div class="col-span-3 row-span-3">
<img src="https://tailus.io/sources/blocks/ecommerce-site/preview/images/products/daniel.webp" class="w-full h-full object-cover object-top rounded-xl" width="640" height="427" alt="shoes" loading="lazy">
</div>
</div>
</div>
</div>
</div>
How to create a Call To Action with Tailwind CSS?
Install tailwind css of verion 2.2.19
Use the script
html tag to import the script of Tailwind CSS of the version 2.2.19
<script src="https://cdn.tailwindcss.com"></script>
All the unility class needed to create a Call To Action component
py-16
bg-white
m-auto
px-6
text-gray-500
md:px-12
lg:px-20
text-center
gap-6
md:text-left
md:flex
lg:gap-16
mb-6
md:mb-0
md:w-6/12
lg:w-6/12
text-4xl
text-gray-700
md:text-5xl
text-blue-500
text-lg
flex
flex-row-reverse
flex-wrap
gap-4
md:gap-6
w-full
py-3
bg-gray-700
hover:bg-gray-600
active:bg-gray-700
focus:bg-gray-600
sm:w-max
block
text-white
bg-gray-100
hover:bg-gray-200
active:bg-gray-300
focus:bg-gray-200
text-gray-600
grid
grid-cols-5
grid-rows-4
md:w-5/12
h-full
45 steps to create a Call To Action component with Tailwind CSS
Control the vertical padding of an element to 4rem using the
py-16
utilities.Control the background color of an element to white using the
bg-white
utilities.Control the margin on all sides of an element to auto using the
m-auto
utilities.Control the horizontal padding of an element to 1.5rem using the
px-6
utilities.Control the text color of an element to gray-500 using the
text-gray-500
utilities.Control the horizontal padding of an element to 3rem at only medium screen sizes using the
md:px-12
utilities.Control the horizontal padding of an element to 5rem at only large screen sizes using the
lg:px-20
utilities.Control the text color of an element to center using the
text-center
utilities.To specify the width between columns, you can use the
gap-6
utilities.Control the text color of an element to left at only medium screen sizes using the
md:text-left
utilities.Use
flex
to create a block-level flex container at only medium screen sizes.To specify the width between columns at only large screen sizes, you can use the
lg:gap-16
utilities.Control the margin on bottom side of an element to 1.5rem using the
mb-6
utilities.Control the margin on bottom side of an element to 0rem at only medium screen sizes using the
md:mb-0
utilities.Use
md:w-6/12
to set an element to a fixed width(6/12) at only medium screen sizes.Use
lg:w-6/12
to set an element to a fixed width(6/12) at only large screen sizes.Control the text color of an element to 4xl using the
text-4xl
utilities.Control the text color of an element to gray-700 using the
text-gray-700
utilities.Control the text color of an element to 5xl at only medium screen sizes using the
md:text-5xl
utilities.Control the text color of an element to blue-500 using the
text-blue-500
utilities.Control the text color of an element to lg using the
text-lg
utilities.Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.To specify the width between columns, you can use the
gap-4
utilities.To specify the width between columns at only medium screen sizes, you can use the
md:gap-6
utilities.Use
w-full
to set an element to a 100% based width.Control the vertical padding of an element to 0.75rem using the
py-3
utilities.Control the background color of an element to gray-700 using the
bg-gray-700
utilities.Control the background color of an element to gray-600 using the
hover:bg-gray-600
utilities on hover.Control the background color of an element to gray-700 using the
active:bg-gray-700
utilities on active.Control the background color of an element to gray-600 using the
focus:bg-gray-600
utilities on focus.Use
sm:w-max
to set an element to a fixed width(max) at only small screen sizes.Use
inline
utilities to put the element on its own line and fill its parent.Control the text color of an element to white using the
text-white
utilities.Control the background color of an element to gray-100 using the
bg-gray-100
utilities.Control the background color of an element to gray-200 using the
hover:bg-gray-200
utilities on hover.Control the background color of an element to gray-300 using the
active:bg-gray-300
utilities on active.Control the background color of an element to gray-200 using the
focus:bg-gray-200
utilities on focus.Control the text color of an element to gray-600 using the
text-gray-600
utilities.Use
grid
to create a grid container.Use
grid
to create a grid container.Use
grid
to create a grid container.Use
md:w-5/12
to set an element to a fixed width(5/12) at only medium screen sizes.Use
h-full
to set an element’s height to 100% of its parent, as long as the parent has a defined height.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to create a Call To Action components, learn and follow along to implement your own components.