Animate emojis like on Discord with JavaScript

Would you like to create a button whose emoji changes every time you move your mouse over it? Like on Discord? Then this article is for you!
β€’
Updated on August 14, 2026
β€’
1 min read
Believemy logo

Want to create a button whose emoji changes with every mouse hover? Like on Discord? Then this article is for you!

Image

Β 

Step 1

The HTML code.

HTML
<div id="emoji">😁</div>

Nothing very complicated here: we declare a division with an id emoji.

Tip: Get your emojis from getemoji.com

Β 

Step 2

Now let's style the id emoji.

CSS
#emoji {
      font-size: 5rem;
      filter: grayscale(1);
      cursor: pointer;
      transition: all 0.2s;
    }
    
    #emoji:hover {
      transform: scale(1.3);
      filter: grayscale(0);
    }

The grayscale() property allows you to transform an image into grayscale colors.

Β 

Step 3

Let's move on to JavaScript by adding emojis.

JAVASCRIPT
const btn = document.querySelector("#emoji");
const emojis = [
  "πŸ˜†", "πŸ˜…", "🀣", "πŸ˜‚",
  "πŸ˜€", "πŸ€‘", "🀨", "πŸ™‚",
  "😊", "πŸ˜—", "πŸ˜›", "😏",
  "πŸ€₯", "😴", "πŸ₯Ί", "😧"
];

Β 

Step 4

Let's detect the emoji hover.

JAVASCRIPT
btn.addEventListener("mouseover", () => {
  btn.innerText = emojis[Math.floor(Math.random() * emojis.length)];
});

As soon as we hover over the emoji, we replace the text of the id emoji with a new emoji.

To do this, we generate a random number and multiply it by the number of emojis we have.

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

Create an animated "rainbow" button with CSS

In this article, we'll show you how to create a rainbow button that comes to life when the mouse hovers over it. A modern and sensational effect guaranteed!

December 9, 2024

Creating circled buttons on hover with HTML and CSS

For a menu or to encourage your readers to share your website, share buttons are essential elements to add to your website. Let's find out how to make them more modern with a "neon" effect that will surround the icon selected by your user.

December 9, 2024

Create an animated 3D button using CSS

In this article, we'll find out how to create a three-dimensional button that will add a touch of softness and perspective to your projects!

December 9, 2024

Create a button that moves with the mouse using Tilt.js

Do you have a main button? Would you like to animate it with a dynamic, modern interaction? Let's learn how with the Tilt.JS library!

December 9, 2024

Create a map displaying links on mouse-over with CSS

To present your team or simply yourself, this animation will allow you to display the links to your social networks when you hover over the map: a striking effect guaranteed! Let's find out how to do it together.

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

Create a very modern hover on a link

Here's an easy way to create a very modern hover on a link! There are lots of possible effects for buttons and links: the better they look, the more likely your users will be to click on them.

December 9, 2024

Create a glitch effect on mouse-over with CSS

Add a modern glitch effect to your presentations or your logo, whether it's hovering or permanent! Let's find out how.

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.