Published on

A Complete Guide To Make A Notification Toast With Tailwind CSS

Tags
Notification toast

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 toast ui component

Flexible and fully customizable toast

Why use Tailwind CSS to build a Notification toast ui component?

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

The preview of Notification toast ui component

Free download of the Notification toast's source code

The source code of Notification toast ui component

<div class="grid grid-cols-1 gap-2 justify-center items-center">
	<!-- Danger -->
	<div class='flex items-center text-white max-w-sm w-full bg-red-400 shadow-md rounded-lg overflow-hidden mx-auto'>
		<div class='w-10 border-r px-2'>
			<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"
				xmlns="http://www.w3.org/2000/svg">
				<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
					d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636">
				</path>
			</svg>
		</div>

		<div class='flex items-center px-2 py-3'>


			<div class='mx-3'>
				<p>Your message</p>
			</div>
		</div>
	</div>

	<!-- succes -->
	<div class='flex items-center text-white max-w-sm w-full bg-green-400 shadow-md rounded-lg overflow-hidden mx-auto'>
		<div class='w-10 border-r px-2'>
			<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"
				xmlns="http://www.w3.org/2000/svg">
				<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
					d="M9 12l2 2 4-4M7.835 4.697a3.42 3.42 0 001.946-.806 3.42 3.42 0 014.438 0 3.42 3.42 0 001.946.806 3.42 3.42 0 013.138 3.138 3.42 3.42 0 00.806 1.946 3.42 3.42 0 010 4.438 3.42 3.42 0 00-.806 1.946 3.42 3.42 0 01-3.138 3.138 3.42 3.42 0 00-1.946.806 3.42 3.42 0 01-4.438 0 3.42 3.42 0 00-1.946-.806 3.42 3.42 0 01-3.138-3.138 3.42 3.42 0 00-.806-1.946 3.42 3.42 0 010-4.438 3.42 3.42 0 00.806-1.946 3.42 3.42 0 013.138-3.138z">
				</path>
			</svg>
		</div>

		<div class='flex items-center px-2 py-3'>


			<div class='mx-3'>
				<p>Your message</p>
			</div>
		</div>
	</div>

	<!-- warning -->
	<div
		class='flex items-center text-white max-w-sm w-full bg-yellow-400 shadow-md rounded-lg overflow-hidden mx-auto'>
		<div class='w-10 border-r px-2'>
			<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"
				xmlns="http://www.w3.org/2000/svg">
				<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
					d="M20.618 5.984A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016zM12 9v2m0 4h.01">
				</path>
			</svg>
		</div>

		<div class='flex items-center px-2 py-3'>


			<div class='mx-3'>
				<p>Your message</p>
			</div>
		</div>
	</div>
	<!-- info -->
	<div class='flex items-center text-white max-w-sm w-full bg-blue-400 shadow-md rounded-lg overflow-hidden mx-auto'>
		<div class='w-10 border-r px-2'>
			<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"
				xmlns="http://www.w3.org/2000/svg">
				<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
					d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
			</svg>
		</div>

		<div class='flex items-center px-2 py-3'>


			<div class='mx-3'>
				<p>Your message</p>
			</div>
		</div>
	</div>

</div>

How to build a Notification toast with Tailwind CSS?

Install tailwind css of verion 2.0.3

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

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

All the unility class needed to build a Notification toast component

  • grid
  • grid-cols-1
  • gap-2
  • w-6
  • h-6

5 steps to build a Notification toast component with Tailwind CSS

  1. Use grid to create a grid container.

  2. Use grid to create a grid container.

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

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

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

Conclusion

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