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!
•
Updated on August 14, 2026
•
2 min read
Believemy logo

Let's discover in this article how to create a "rainbow" button that animates on mouse hover. A modern and sensational effect guaranteed!

Image

 

Step 1

The HTML code.

HTML
<button>
  Click me
</button>

Our HTML code consists of a simple button. We couldn't make it any simpler, could we?

 

Step 2

Let's style our button.

CSS
button {
  padding: 20px 50px;
  font-size: 1.5rem;
  cursor: pointer;
  border: 0px;
  background: transparent;
  position: relative;
  transition: all .2s;
  overflow: hidden;
  color: #fff;
  border-radius: 30px;
  box-shadow: 0px -0px 0px 0px rgba(143, 64, 248, .5), 0px 0px 0px 0px rgba(39, 200, 255, .5);
}

In the previous step, we created a “rainbow” square. It is simply a 400px by 400px square that we offset to the side using the top and left properties to capture the most beautiful part of the gradient.

 

Step 3

Let's add a rainbow square.

CSS
button::after {
  content: '';
  width: 400px;
  height: 400px;
  position: absolute;
  top: -50px;
  left: -100px;
  background-image: linear-gradient(225deg, 
#27d86c 0%, #26caf8 50%, #c625d0 100%);
  z-index: -1;
  transition: all .5s;
}

In this step, we style the button::after pseudo-element to create the rainbow square. This square will serve as the background for our button, and it will not overflow thanks to the overflow: hidden property we added in step 2.

 

Step 4

Let's add hover effects.

CSS
button:hover::after {
  transform: rotate(150deg);
}

button:hover {
  transform: translate(0, -6px);
  box-shadow: 10px -10px 25px 0px rgba(143, 64, 248, .25), -10px 10px 25px 0px rgba(39, 200, 255, .25);
}

Here, we simply rotate our rainbow square to change the gradient displayed in the button's background.
We also take the opportunity to raise it upwards using the transform property and add a more significant shadow using the box-shadow property.

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 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 an "architectural" design button using CSS

Creating a button where the borders split in two on hover may seem complicated, but nothing could be easier! Let's find out how in this article.

December 9, 2024

Creating an "Old School" button with CSS

Let's find out how to create an original button that's right up to date!

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

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

Creating a button with a "fill" effect using CSS

In this article, we'll be taking a look at the secret to achieving this "filling" effect on a button!

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

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

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.