Published on

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

Call To Action

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

  1. Control the vertical padding of an element to 4rem using the py-16 utilities.

  2. Control the background color of an element to white using the bg-white utilities.

  3. Control the margin on all sides of an element to auto using the m-auto utilities.

  4. Control the horizontal padding of an element to 1.5rem using the px-6 utilities.

  5. Control the text color of an element to gray-500 using the text-gray-500 utilities.

  6. Control the horizontal padding of an element to 3rem at only medium screen sizes using the md:px-12 utilities.

  7. Control the horizontal padding of an element to 5rem at only large screen sizes using the lg:px-20 utilities.

  8. Control the text color of an element to center using the text-center utilities.

  9. To specify the width between columns, you can use the gap-6 utilities.

  10. Control the text color of an element to left at only medium screen sizes using the md:text-left utilities.

  11. Use flex to create a block-level flex container at only medium screen sizes.

  12. To specify the width between columns at only large screen sizes, you can use the lg:gap-16 utilities.

  13. Control the margin on bottom side of an element to 1.5rem using the mb-6 utilities.

  14. Control the margin on bottom side of an element to 0rem at only medium screen sizes using the md:mb-0 utilities.

  15. Use md:w-6/12 to set an element to a fixed width(6/12) at only medium screen sizes.

  16. Use lg:w-6/12 to set an element to a fixed width(6/12) at only large screen sizes.

  17. Control the text color of an element to 4xl using the text-4xl utilities.

  18. Control the text color of an element to gray-700 using the text-gray-700 utilities.

  19. Control the text color of an element to 5xl at only medium screen sizes using the md:text-5xl utilities.

  20. Control the text color of an element to blue-500 using the text-blue-500 utilities.

  21. Control the text color of an element to lg using the text-lg utilities.

  22. Use flex to create a block-level flex container.

  23. Use flex to create a block-level flex container.

  24. Use flex to create a block-level flex container.

  25. To specify the width between columns, you can use the gap-4 utilities.

  26. To specify the width between columns at only medium screen sizes, you can use the md:gap-6 utilities.

  27. Use w-full to set an element to a 100% based width.

  28. Control the vertical padding of an element to 0.75rem using the py-3 utilities.

  29. Control the background color of an element to gray-700 using the bg-gray-700 utilities.

  30. Control the background color of an element to gray-600 using the hover:bg-gray-600 utilities on hover.

  31. Control the background color of an element to gray-700 using the active:bg-gray-700 utilities on active.

  32. Control the background color of an element to gray-600 using the focus:bg-gray-600 utilities on focus.

  33. Use sm:w-max to set an element to a fixed width(max) at only small screen sizes.

  34. Use inline utilities to put the element on its own line and fill its parent.

  35. Control the text color of an element to white using the text-white utilities.

  36. Control the background color of an element to gray-100 using the bg-gray-100 utilities.

  37. Control the background color of an element to gray-200 using the hover:bg-gray-200 utilities on hover.

  38. Control the background color of an element to gray-300 using the active:bg-gray-300 utilities on active.

  39. Control the background color of an element to gray-200 using the focus:bg-gray-200 utilities on focus.

  40. Control the text color of an element to gray-600 using the text-gray-600 utilities.

  41. Use grid to create a grid container.

  42. Use grid to create a grid container.

  43. Use grid to create a grid container.

  44. Use md:w-5/12 to set an element to a fixed width(5/12) at only medium screen sizes.

  45. 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.