Published on

Ultimate Guide: Make A Simple Alerts With Tailwind CSS

Tags
Simple Alerts

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 Simple Alerts ui component

Example of some alerts

Why use Tailwind CSS to create a Simple Alerts ui component?

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

The preview of Simple Alerts ui component

Free download of the Simple Alerts's source code

The source code of Simple Alerts ui component

<header>
      <div class="text-center text-4xl text-gray-800 font-bold mx-auto my-10">
        Simple Alerts
      </div>
    </header>

    <main class="px-4 flex-grow flex justify-center items-center text-center container mx-auto  grid row-gap-4 grid-cols-1 w-full">


      <div class="grid grid-cols-1 gap-4 w-full bg-white p-6 border border-gray-500 rounded-sm">

        <div class="my-8 text-left">
          <h2 class="text-gray-700">Basic Alert</h2>
       </div>

        <div class="block text-sm text-left text-gray-600 bg-gray-200 border border-gray-400 h-12 flex items-center p-4 rounded-sm" role="alert">
          This is a default alert—check it out!
        </div>

        <div class="block text-sm text-left text-purple-600 bg-purple-200 border border-purple-400 h-12 flex items-center p-4 rounded-sm" role="alert">
          This is a primary alert—check it out!
        </div>

        <div class="block text-sm text-left text-indigo-600 bg-indigo-200 border border-indigo-400 h-12 flex items-center p-4 rounded-sm" role="alert">
          This is a success alert—check it out!
        </div>

        <div class="block text-sm text-left text-blue-600 bg-blue-200 border border-blue-400 h-12 flex items-center p-4 rounded-sm" role="alert">
          This is a info alert—check it out!
        </div>

        <div class="block text-sm text-left text-yellow-600 bg-yellow-200 border border-yellow-400 h-12 flex items-center p-4 rounded-sm" role="alert">
          This is a warning alert—check it out!
        </div>

        <div class="block text-sm text-left text-red-600 bg-red-200 border border-red-400 h-12 flex items-center p-4 rounded-sm" role="alert">
          This is a danger alert—check it out!
        </div>

      </div>

      <div class="grid grid-cols-1 gap-4 w-full bg-white p-6 border border-gray-500 rounded-sm">

        <div class="my-8 text-left">
          <h2 class="text-gray-700">Dismissible Alerts</h2>
       </div>

        <div class="block text-sm text-red-600 bg-red-200 border border-red-400 h-12 flex items-center p-4 rounded-sm relative" role="alert">
          <strong class="mr-1">Holy Sh...t!</strong> Something seriously bad happened..
          <button type="button" data-dismiss="alert" aria-label="Close" onclick="this.parentElement.remove();">
              <span class="absolute top-0 bottom-0 right-0 text-2xl px-3 py-1 hover:text-red-900" aria-hidden="true" >×</span>
          </button>
        </div>

      </div>

      <div class="grid grid-cols-1 gap-4 w-full bg-white p-6 border border-gray-500 rounded-sm">

        <div class="my-8 text-left">
          <h2 class="text-gray-700">Additional content</h2>
        </div>

        <div class="text-sm text-left text-indigo-600 bg-indigo-200 border border-indigo-400 h-30 p-4 rounded-sm" role="alert">

          <strong class="">Well done!</strong>
          <p class="py-2">Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>

          <hr class="border-indigo-400 my-2">
          <p class="py-2">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>

        </div>

      </div>

      <div class="grid grid-cols-1 gap-4 w-full bg-white p-6 border border-gray-500 rounded-sm">

        <div class="my-8 text-left">
          <h2 class="text-gray-700">Alert With Icons</h2>
       </div>

        <div class="block text-sm text-blue-600 bg-blue-200 border border-blue-400 h-12 flex items-center p-4 rounded-sm relative" role="alert">
          <span class="mr-1">
            <svg class="fill-current text-blue-500 inline-block h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
              <path class="heroicon-ui" d="M15 19a3 3 0 0 1-6 0H4a1 1 0 0 1 0-2h1v-6a7 7 0 0 1 4.02-6.34 3 3 0 0 1 5.96 0A7 7 0 0 1 19 11v6h1a1 1 0 0 1 0 2h-5zm-4 0a1 1 0 0 0 2 0h-2zm0-12.9A5 5 0 0 0 7 11v6h10v-6a5 5 0 0 0-4-4.9V5a1 1 0 0 0-2 0v1.1z"/>
            </svg>
          </span>
          <span>
            <strong class="mr-1">Holy Sh...t!</strong> Something seriously bad happened..
          </span>
        </div>

      </div>

      <div class="grid grid-cols-1 gap-4 w-full bg-white p-6 border border-gray-500 rounded-sm">

        <div class="my-8 text-left">
          <h2 class="text-gray-700">Alert With Icons</h2>
       </div>

        <div class="block text-sm text-gray-600 bg-white h-12 flex items-center p-4 rounded-md shadow-float" role="alert">
          <span>
            <strong class="mr-1">Holy Sh...t!</strong> Something seriously bad happened..
          </span>
        </div>

      </div>

    </main>

How to create a Simple Alerts 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 create a Simple Alerts component

  • text-center
  • text-4xl
  • text-gray-800
  • mx-auto
  • my-10
  • px-4
  • flex-grow
  • flex
  • grid
  • grid-cols-1
  • w-full
  • gap-4
  • bg-white
  • p-6
  • border-gray-500
  • my-8
  • text-left
  • text-gray-700
  • block
  • text-sm
  • text-gray-600
  • bg-gray-200
  • border-gray-400
  • h-12
  • p-4
  • text-purple-600
  • bg-purple-200
  • border-purple-400
  • text-indigo-600
  • bg-indigo-200
  • border-indigo-400
  • text-blue-600
  • bg-blue-200
  • border-blue-400
  • text-yellow-600
  • bg-yellow-200
  • border-yellow-400
  • text-red-600
  • bg-red-200
  • border-red-400
  • relative
  • mr-1
  • absolute
  • top-0
  • bottom-0
  • right-0
  • text-2xl
  • px-3
  • py-1
  • hover:text-red-900
  • h-30
  • py-2
  • my-2
  • text-blue-500
  • inline-block
  • h-5
  • w-5

57 steps to create a Simple Alerts component with Tailwind CSS

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

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

  3. Control the text color of an element to gray-800 using the text-gray-800 utilities.

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

  5. Control the vertical margin of an element to 2.5rem using the my-10 utilities.

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

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

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

  9. Use grid to create a grid container.

  10. Use grid to create a grid container.

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

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

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

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

  15. Control the border color of an element to gray-500 using the border-gray-500 utilities.

  16. Control the vertical margin of an element to 2rem using the my-8 utilities.

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

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

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

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

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

  22. Control the background color of an element to gray-200 using the bg-gray-200 utilities.

  23. Control the border color of an element to gray-400 using the border-gray-400 utilities.

  24. Use h-12 to set an element to a fixed height(3rem).

  25. Control the padding on all sides of an element to 1rem using the p-4 utilities.

  26. Control the text color of an element to purple-600 using the text-purple-600 utilities.

  27. Control the background color of an element to purple-200 using the bg-purple-200 utilities.

  28. Control the border color of an element to purple-400 using the border-purple-400 utilities.

  29. Control the text color of an element to indigo-600 using the text-indigo-600 utilities.

  30. Control the background color of an element to indigo-200 using the bg-indigo-200 utilities.

  31. Control the border color of an element to indigo-400 using the border-indigo-400 utilities.

  32. Control the text color of an element to blue-600 using the text-blue-600 utilities.

  33. Control the background color of an element to blue-200 using the bg-blue-200 utilities.

  34. Control the border color of an element to blue-400 using the border-blue-400 utilities.

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

  36. Control the background color of an element to yellow-200 using the bg-yellow-200 utilities.

  37. Control the border color of an element to yellow-400 using the border-yellow-400 utilities.

  38. Control the text color of an element to red-600 using the text-red-600 utilities.

  39. Control the background color of an element to red-200 using the bg-red-200 utilities.

  40. Control the border color of an element to red-400 using the border-red-400 utilities.

  41. Use relative to position an element according to the normal flow of the document.

  42. Control the margin on right side of an element to 0.25rem using the mr-1 utilities.

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

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

  45. Use the bottom-0 utilities to set the bottom position of a positioned element to 0rem.

  46. Use the right-0 utilities to set the right position of a positioned element to 0rem.

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

  48. Control the horizontal padding of an element to 0.75rem using the px-3 utilities.

  49. Control the vertical padding of an element to 0.25rem using the py-1 utilities.

  50. Control the text color of an element to red-900 on hover using the hover:text-red-900 utilities.

  51. Use h-30 to set an element to a fixed height(7.5rem).

  52. Control the vertical padding of an element to 0.5rem using the py-2 utilities.

  53. Control the vertical margin of an element to 0.5rem using the my-2 utilities.

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

  55. Use inline-block utilities to wrap the element to prevent the text inside from extending beyond its parent.

  56. Use h-5 to set an element to a fixed height(1.25rem).

  57. Use w-5 to set an element to a fixed width(1.25rem).

Conclusion

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