Published on

How to Make A Toaster Notification With Tailwind CSS?

Tags
Toaster Notification

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

Simple toaster notification

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

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

The preview of Toaster Notification ui component

Free download of the Toaster Notification's source code

The source code of Toaster Notification ui component

<div class="w-full h-screen flex flex-col items-center justify-center">
    <div class="mb-4">
        <div class="flex max-w-sm w-full bg-white shadow-md rounded-lg overflow-hidden mx-auto">
            <div class="w-2 bg-red-600">
            </div>
            <div class="w-full flex justify-between items-start px-2 py-2">
                <div class="flex flex-col ml-2">
                    <label class="text-gray-800">Your submission was rejected</label>
                    <p class="text-gray-500 ">Lorem ipsum dolor sit amet consectetur sit amet
                </div>
                <a href="#">
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                    </svg>
                </a>
            </div>
        </div>
    </div>
    <div class="mb-4">
        <div class="flex max-w-sm w-full bg-white shadow-md rounded-lg overflow-hidden mx-auto">
            <div class="w-2 bg-green-600">
            </div>
            <div class="w-full flex justify-between items-start px-2 py-2">
                <div class="flex flex-col ml-2">
                    <label class="text-gray-800">Your submission was approved</label>
                    <p class="text-gray-500 ">Lorem ipsum dolor sit amet consectetur sit amet
                </div>
                <a href="#">
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                    </svg>
                </a>
            </div>
        </div>
    </div>
    <div class="mb-4">
        <div class="flex max-w-sm w-full bg-white shadow-md rounded-lg overflow-hidden mx-auto">
            <div class="w-2 bg-yellow-600">
            </div>
            <div class="w-full flex justify-between items-start px-2 py-2">
                <div class="flex flex-col ml-2">
                    <label class="text-gray-800">Your submission is pending</label>
                    <p class="text-gray-500 ">Lorem ipsum dolor sit amet consectetur sit amet
                </div>
                <a href="#">
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                    </svg>
                </a>
            </div>
        </div>
    </div>
</div>

How to make a Toaster Notification 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 Toaster Notification component

  • w-full
  • h-screen
  • flex
  • flex-col
  • mb-4
  • max-w-sm
  • bg-white
  • overflow-hidden
  • mx-auto
  • w-2
  • bg-red-600
  • px-2
  • py-2
  • ml-2
  • text-gray-800
  • text-gray-500
  • h-6
  • w-6
  • bg-green-600
  • bg-yellow-600

20 steps to make a Toaster Notification component with Tailwind CSS

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

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

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

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

  5. Control the margin on bottom side of an element to 1rem using the mb-4 utilities.

  6. Set the maximum width/height of an element using the max-w-sm utilities.

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

  8. Use overflow-hidden to clip any content within an element that overflows the bounds of that element.

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

  10. Use w-2 to set an element to a fixed width(0.5rem).

  11. Control the background color of an element to red-600 using the bg-red-600 utilities.

  12. Control the horizontal padding of an element to 0.5rem using the px-2 utilities.

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

  14. Control the margin on left side of an element to 0.5rem using the ml-2 utilities.

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

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

  17. Use h-6 to set an element to a fixed height(1.5rem).

  18. Use w-6 to set an element to a fixed width(1.5rem).

  19. Control the background color of an element to green-600 using the bg-green-600 utilities.

  20. Control the background color of an element to yellow-600 using the bg-yellow-600 utilities.

Conclusion

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