Published on

6 Ideas To Help You Build A Modals With TailwindV3 With Tailwind CSS Like A Pro

Modals with TailwindV3

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 Modals with TailwindV3 ui component

Centered with single action. follow me for more designs from tailwindui.com. design from tailwindui.com/components/application-ui/overlays/modals#heading-31555aec01de5027d6696629eb60f673

Why use Tailwind CSS to create a Modals with TailwindV3 ui component?

  • It can make the building process of Modals with TailwindV3 ui component faster and more easily.
  • Enables building complex responsive layouts and components freely.
  • Minimum lines of CSS code in Modals with TailwindV3 component file.

The preview of Modals with TailwindV3 ui component

Free download of the Modals with TailwindV3's source code

The source code of Modals with TailwindV3 ui component

<script src="https://cdn.tailwindcss.com/"></script>
<div class="w-full min-h-screen flex justify-center items-center bg-black">
  <p id="modal-switch" class="text-[10vw] bg-gradient-to-r from-indigo-500 via-purple-500 text-transparent bg-clip-text to-pink-500 font-bold cursor-pointer">Click Me</p>
</div>
<!-- Modal  -->
<div class="w-full h-full">
  <div id="modal-bg" class="w-full h-full bg-[#848A97] top-0 absolute hidden"></div>
  <div id="modal-box" class="sm:w-[385px] sm:min-w-[40vw] min-w-[80vw] min-h-[50vh] flex flex-col items-center gap-2 -translate-y-1/2 p-6 bg-[#FFFFEB] rounded-lg top-1/2 left-1/2 -translate-x-1/2 absolute hidden">
    <svg xmlns="http://www.w3.org/2000/svg" class="text-[#059669] mx-auto h-11 rounded-full bg-[#D1FAE5] w-11" fill="none" viewBox="0 0 24 24" stroke="currentColor">
      <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M5 13l4 4L19 7" />
    </svg>
    <span class="text-2xl font-medium">Payment Successful</span>
    <p class="text-center">Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus, consequatur?</p>
    <button id="modal-close" class="p-3 bg-[#4F46E5] rounded-lg w-full text-white">Click Background</button>
  </div>
</div>
<script>
  const modalbg = document.getElementById('modal-bg');
  const modalSwitch = document.getElementById('modal-switch');
  const modalBox = document.getElementById('modal-box');
  const modalClose = document.getElementById('modal-close');
  modalbg.addEventListener("click", function() {
    modalBox.classList.add('hidden')
    modalbg.classList.add('hidden')
  });
  modalSwitch.addEventListener("click", function() {
    modalBox.classList.remove('hidden')
    modalbg.classList.remove('hidden')
  });
  modalClose.addEventListener("click", function() {
    modalBox.classList.remove('hidden')
    modalbg.classList.remove('hidden')
  });
</script>

How to create a Modals with TailwindV3 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 Modals with TailwindV3 component

  • w-full
  • min-h-screen
  • flex
  • bg-black
  • text-[10vw]
  • bg-gradient-to-r
  • text-transparent
  • bg-clip-text
  • h-full
  • bg-[#848A97]
  • top-0
  • absolute
  • hidden
  • sm:w-[385px]
  • sm:min-w-[40vw]
  • min-w-[80vw]
  • min-h-[50vh]
  • flex-col
  • gap-2
  • p-6
  • bg-[#FFFFEB]
  • top-1/2
  • left-1/2
  • text-[#059669]
  • mx-auto
  • h-11
  • bg-[#D1FAE5]
  • w-11
  • text-2xl
  • text-center
  • p-3
  • bg-[#4F46E5]
  • text-white

33 steps to create a Modals with TailwindV3 component with Tailwind CSS

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

  2. Set the minimum width/height of an element using the min-h-screen utilities.

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

  4. Control the background color of an element to black using the bg-black utilities.

  5. Control the text color of an element to [10vw] using the text-[10vw] utilities.

  6. Control the background color of an element to gradient-to-r using the bg-gradient-to-r utilities.

  7. Control the text color of an element to transparent using the text-transparent utilities.

  8. Control the background color of an element to clip-text using the bg-clip-text utilities.

  9. Use h-full to set an element’s height to 100% of its parent, as long as the parent has a defined height.

  10. Control the background color of an element to [#848A97] using the bg-[#848A97] utilities.

  11. Use the top-0 utilities to set the top position of a positioned element to 0rem.

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

  13. Use hidden to set an element to display: none and remove it from the page layout.

  14. Use sm:w-[385px] to set an element to a fixed width([385px]) at only small screen sizes.

  15. Set the minimum width/height of an element using the sm:min-w-[40vw] utilities at only small screen sizes.

  16. Set the minimum width/height of an element using the min-w-[80vw] utilities.

  17. Set the minimum width/height of an element using the min-h-[50vh] utilities.

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

  19. To specify the width between columns, you can use the gap-2 utilities.

  20. Control the padding on all sides of an element to 1.5rem using the p-6 utilities.

  21. Control the background color of an element to [#FFFFEB] using the bg-[#FFFFEB] utilities.

  22. Use the top-1/2 utilities to set the top position of a positioned element to 1/2.

  23. Use the left-1/2 utilities to set the left position of a positioned element to 1/2.

  24. Control the text color of an element to [#059669] using the text-[#059669] utilities.

  25. Control the horizontal margin of an element to auto using the mx-auto utilities.

  26. Use h-11 to set an element to a fixed height(2.75rem).

  27. Control the background color of an element to [#D1FAE5] using the bg-[#D1FAE5] utilities.

  28. Use w-11 to set an element to a fixed width(2.75rem).

  29. Control the text color of an element to 2xl using the text-2xl utilities.

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

  31. Control the padding on all sides of an element to 0.75rem using the p-3 utilities.

  32. Control the background color of an element to [#4F46E5] using the bg-[#4F46E5] utilities.

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

Conclusion

The above is a step-by-step tutorial on how to use Tailwind CSS to create a Modals with TailwindV3 components, learn and follow along to implement your own components.