Published on

How To Create A Notification Alert With Tailwind CSS In 6 Easy Steps?

Tags
Notification alert

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 Notification alert ui component

Simple notification alert boxes

Why use Tailwind CSS to make a Notification alert ui component?

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

The preview of Notification alert ui component

Free download of the Notification alert's source code

The source code of Notification alert ui component

<div class="max-w-lg mx-auto items-center h-screen">
    <div class="flex justify-between px-3 py-1 bg-white items-center gap-1 rounded-lg border border-gray-100 my-3">
        <div class="relative w-16 h-16 rounded-full hover:bg-red-700 bg-gradient-to-r from-purple-400 via-blue-500 to-red-400 ">
            <div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-14 h-14 bg-gray-200 rounded-full border-2 border-white">
                <img class="w-full h-full object-cover rounded-full" src="https://d2qp0siotla746.cloudfront.net/img/use-cases/profile-picture/template_3.jpg" alt="">
            </div>
        </div>
        <div>
            <span class="font-mono">Emma would like to connect with you</span>
        </div>
        <div class="flex gap-2">
            <button>
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                    <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
                  </svg>
            </button>
            <button>
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                    <path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" />
                  </svg>
            </button>
        </div>
    </div>

    <div class="flex justify-between px-3 py-1 bg-white items-center gap-1 rounded-lg border border-gray-100 my-3">
        <div class="relative w-16 h-16 rounded-full hover:bg-red-700 bg-gradient-to-r from-purple-400 via-blue-500 to-red-400 ">
            <div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-14 h-14 bg-gray-200 rounded-full border-2 border-white">
                <img class="w-full h-full object-cover rounded-full" src="https://images.unsplash.com/photo-1463453091185-61582044d556?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80" alt="">
            </div>
        </div>
        <div>
            <span class="font-mono">Tom liked one of your comments</span>
        </div>
        <div>
            <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                <path fill-rule="evenodd" d="M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z" clip-rule="evenodd" />
            </svg>
        </div>
    </div>

    <div class="flex justify-between px-3 py-1 bg-white items-center gap-1 rounded-lg border border-gray-100 my-3">
        <div class="relative w-16 h-16 rounded-full hover:bg-red-700 bg-gradient-to-r from-purple-400 via-blue-500 to-red-400 ">
            <div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-14 h-14 bg-gray-200 rounded-full border-2 border-white">
                <img class="w-full h-full object-cover rounded-full" src="https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=687&q=80" alt="">
            </div>
        </div>
        <div>
            <span class="font-mono">Andrea posted a new Tweet have a look</span>
        </div>
        <div>
            <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                <path d="M10 2a6 6 0 00-6 6v3.586l-.707.707A1 1 0 004 14h12a1 1 0 00.707-1.707L16 11.586V8a6 6 0 00-6-6zM10 18a3 3 0 01-3-3h6a3 3 0 01-3 3z" />
            </svg>
        </div>
    </div>
</div>

How to make a Notification alert with Tailwind CSS?

Install tailwind css of verion 2.2.4

Use the script html tag to import the script of Tailwind CSS of the version 2.2.4

<script src="https://cdn.tailwindcss.com"></script>

All the unility class needed to make a Notification alert component

  • max-w-lg
  • mx-auto
  • h-screen
  • flex
  • px-3
  • py-1
  • bg-white
  • gap-1
  • border-gray-100
  • my-3
  • relative
  • w-16
  • h-16
  • hover:bg-red-700
  • bg-gradient-to-r
  • absolute
  • top-1/2
  • left-1/2
  • w-14
  • h-14
  • bg-gray-200
  • border-2
  • border-white
  • w-full
  • h-full
  • gap-2
  • h-5
  • w-5

28 steps to make a Notification alert component with Tailwind CSS

  1. Set the maximum width/height of an element using the max-w-lg utilities.

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

  3. Use h-screen to make an element span the entire height of the viewport.

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

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

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

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

  8. To specify the width between columns, you can use the gap-1 utilities.

  9. Control the border color of an element to gray-100 using the border-gray-100 utilities.

  10. Control the vertical margin of an element to 0.75rem using the my-3 utilities.

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

  12. Use w-16 to set an element to a fixed width(4rem).

  13. Use h-16 to set an element to a fixed height(4rem).

  14. Control the background color of an element to red-700 using the hover:bg-red-700 utilities on hover.

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

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

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

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

  19. Use w-14 to set an element to a fixed width(3.5rem).

  20. Use h-14 to set an element to a fixed height(3.5rem).

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

  22. Control the border color of an element to 0.5rem using the border-2 utilities.

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

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

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

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

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

  28. 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 make a Notification alert components, learn and follow along to implement your own components.