- Published on
How To Make A Simple toast With Tailwind CSS In 6 Easy Steps?

- What is Tailwind CSS?
- The description of Simple toast ui component
- Why use Tailwind CSS to make a Simple toast ui component?
- The preview of Simple toast ui component
- The source code of Simple toast ui component
- How to make a Simple toast with Tailwind CSS?
- Install tailwind css of verion 3.0.18
- All the unility class needed to make a Simple toast component
- 15 steps to make a Simple toast component with Tailwind CSS
- Conclusion
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 toast ui component
A simple toast with its functionality. a user can click the toast to close it or it will close automatically after 5 seconds.
Why use Tailwind CSS to make a Simple toast ui component?
- It can make the building process of Simple toast ui component faster and more easily.
- Enables building complex responsive layouts and components freely.
- Minimum lines of CSS code in Simple toast component file.
The preview of Simple toast ui component
Free download of the Simple toast's source code
The source code of Simple toast ui component
<link rel="stylesheet" href="https://unpkg.com/[email protected]/css/boxicons.min.css" />
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
<!-- page -->
<main x-data="app" class="min-w-screen flex min-h-screen items-center justify-center">
<!-- toast -->
<button type="button" @click="closeToast()" x-show="open" x-transition.duration.300ms class="fixed top-4 right-4 z-50 rounded-md bg-green-500 px-4 py-2 text-white transition hover:bg-green-600">
<div class="flex items-center space-x-2">
<span class="text-3xl"><i class="bx bx-check"></i></span>
<p class="font-bold">Item Created Successfully!</p>
</div>
</button>
<!-- trigger button -->
<button type="button" @click="openToast()" class="rounded-md bg-blue-500 px-4 py-2 font-bold text-white transition hover:bg-blue-600">Launch toast</button>
</main>
<script>
let timer;
document.addEventListener("alpine:init", () => {
Alpine.data("app", () => ({
open: false,
openToast() {
if (this.open) return;
this.open = true;
// reset time to 0 second
clearTimeout(timer);
// auto close toast after 5 seconds
timer = setTimeout(() => {
this.open = false;
}, 5000);
},
closeToast() {
this.open = false;
},
}));
});
</script>
How to make a Simple toast with Tailwind CSS?
Install tailwind css of verion 3.0.18
Use the script
html tag to import the script of Tailwind CSS of the version 3.0.18
<script src="https://cdn.tailwindcss.com"></script>
All the unility class needed to make a Simple toast component
min-w-screen
flex
min-h-screen
fixed
top-4
right-4
z-50
bg-green-500
px-4
py-2
text-white
hover:bg-green-600
text-3xl
bg-blue-500
hover:bg-blue-600
15 steps to make a Simple toast component with Tailwind CSS
Set the minimum width/height of an element using the
min-w-screen
utilities.Use
flex
to create a block-level flex container.Set the minimum width/height of an element using the
min-h-screen
utilities.Use
fixed
to position an element relative to the browser window.Use the
top-4
utilities to set the top position of a positioned element to 1rem.Use the
right-4
utilities to set the right position of a positioned element to 1rem.Control the stack order (or three-dimensional positioning) of an element to 50 in Tailwind, regardless of order it has been displayed, using the
z-50
utilities.Control the background color of an element to green-500 using the
bg-green-500
utilities.Control the horizontal padding of an element to 1rem using the
px-4
utilities.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.Control the text color of an element to white using the
text-white
utilities.Control the background color of an element to green-600 using the
hover:bg-green-600
utilities on hover.Control the text color of an element to 3xl using the
text-3xl
utilities.Control the background color of an element to blue-500 using the
bg-blue-500
utilities.Control the background color of an element to blue-600 using the
hover:bg-blue-600
utilities on hover.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to make a Simple toast components, learn and follow along to implement your own components.