Make an animated notification message with JavaScript

Whether it's to quickly warn your users that a feature of your site is not yet available or to let them know that an action has been successfully completed, notifications are the simplest and most modern way to set up. Find out how in this article!
β€’
Updated on August 14, 2026
β€’
2 min read
Believemy logo

Whether to quickly inform your users that a feature of your site is not yet available or to notify them that an action has been successfully completed, notifications are the simplest and most modern way to implement them. Let's discover in this article how to do it!

Image

Β 

Step 1

Let's start with the HTML.

HTML
<button>
  Create an account
</button>

<div id="notification">
  πŸŽ‰ Account successfully created πŸŽ‰
</div>

When we click on the button, the notification will appear like magic!

Β 

Step 2

Let's style the button.

CSS
button {
  font-size: 1.2rem;
  color: #fff;
  background: #ff4754;
  padding: 1.2rem 2.4rem;
  border-radius: 0.2rem;
  transition: all 0.2s;
}

button:hover {
  cursor: pointer;
  opacity: 0.8;
}

We continue just by playing with the variables for colors.

Β 

Step 3

Let's take care of the notification.

CSS
#notification {
  position: fixed;
  bottom: -8rem;
  color: #ff4754;
  background: #000;
  padding: 1.2rem 2.4rem;
  border-radius: 0.2rem;
  box-shadow: 3px 6px 12px rgba(0, 0, 0, 0.4);
  transition: all 0.4s;
}

The secret lies in this class. In the previous step, we precisely set that our notification should be hidden thanks to the bottom property.

Β 

Step 4

Let's create the class show.

CSS
#notification.show {
  bottom: 2rem;
}

All that remains is to add and remove the class show from our message.

Β 

Step 5

Let's select our elements with JavaScript.

JAVASCRIPT
const button = document.querySelector('button');
const toast = document.querySelector('#notification');

We simply select our two elements: our button and our message.

Β 

Step 6

JAVASCRIPT
button.addEventListener("click", () => {
  toast.classList.add("show");
  setTimeout(() => {
    toast.classList.remove("show");
  }, 2000);
});

When our user clicks on the button, we add the class show and then remove it after two seconds to make the message disappear.

Category: Developers

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.

Believemy logo
Comments (0)

You need to be logged in to comment on this article: log in or sign up.

Read next

Creating a clock using JavaScript

Imagine a clock that shows the time to your users, on a travel site for example, with the time zone of the destination country? Let's create this magnificent clock together, using JavaScript!

December 9, 2024

Creating animated presentation cards with JavaScript

Whether you're presenting the team behind your project or anything else, using animated presentation cards will give your page a successful finishing touch. Find out how in this article!

December 9, 2024

Create a navigation bar with an animated indicator

Have you always wanted a dynamic navigation bar with an indicator that glides smoothly underneath the new page you're on? This navigation bar is exactly what you need!

December 6, 2024

Create a button with a notification bubble with CSS

Whether in a dashboard or for a notification system, a button displaying the number of events at a glance is a real must-have for your users' experience. Let's take a look at how to create one easily in this article.

December 9, 2024

Create a menu that spans the entire page using CSS

From time to time we have to ask our visitors which page they want to go to, by displaying the main sections of our website. This menu is often not very pleasant to use, so let's find out together in this article how to make it much more modern, with beautiful animations that will make your passers-by want to visit your site!

December 9, 2024

Make an arrow that expands when hovered over with CSS

Whether it's to make your users want to see your project, read your article or access a page on your website, presenting your link with an arrow will make it easier to catch your visitors' eye! Let's find out in this article how to animate this arrow to enhance your readers' experience.

December 9, 2024

Creating a modal window without using JavaScript

Have you often wanted to create a modal window (a window that opens inside your website) but don't know anything about JavaScript? Let's find out how!

December 9, 2024

Creating a NEON button with CSS

Creating a button is one thing! But creating a button that your visitors want to click is something else entirely. In any case, this neon button will catch the eye of everyone who visits your pages.

December 9, 2024

Become the solopreneur you dream of being.

First project, career change, business launch: access our courses, practice on real-world cases, and move forward with clear guidance.