Creating animated borders and rainbow blurs with CSS and JavaScript

Think again: it's not a shadow, it's a trick that will make your visitors think you've added borders and animated rainbow shadows! It's nothing of the sort: no borders or shadows are used in this tutorial. Let's discover the secret behind this trick.
•
Updated on August 14, 2026
•
2 min read
Believemy logo

Don't be mistaken: it's not a shadow, but indeed a trick that will make your visitors believe you have added animated rainbow borders and shadows! It's not true: no borders and no shadows are used in this tutorial. Let's discover together the secret behind this magic trick.

 

Step 1

Let's start with the HTML code.

HTML
<div class="box"></div>

We can hardly do anything more simple.

 

Step 2

Let's take care of the box (.box) class.

CSS
.box {
  width: 400px;
  height: 300px;
  background-color: rgb(31, 31, 31);
  position: relative;
}

We are just creating a box of 400px by 300px.

 

Step 3

Let's now style the pseudo-elements before and after.

CSS
.box::before,
.box::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  background: linear-gradient(45deg, #ff0000, #00f0f0, #00ff00, #0000ff, #ff0000, #00f0f0, #00ff00, #0000ff, #f00f0f);
  width: 100%;
  height: 100%;
  transform: scale(1.02);
  z-index: -1;
  background-size: 500%;
  animation: animate 20s infinite;
}

In this step, we create two elements using the pseudo-elements before and after.

These two elements have a multicolor background that we enlarge by 500% to keep the most beautiful part.

We increase the size of our elements using the transform property by 2%, which allows us to give the impression of already having rainbow borders on our element.

Finally, we use the z-index property to place these elements behind our box, so as not to cover it.

 

Step 4

Add blur to the after element.

CSS
.box::after {
  filter: blur(20px);
}

In this step, we add blur to our after element only, which gives the impression of having a multicolor shadow.

 

Step 5

Let's develop our animation.

CSS
@keyframes animate {
  0% { background-position: 0 0; }
  50% { background-position: 300% 0; }
  100% { background-position: 0 0; }
}

This animation allows us to move our background on our elements, creating this movement effect.

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 gradient background on hover avec CSS

Whether it's to highlight a part of your website or a quote as in this example, generating and adding a gradient to the background can give your website a very modern touch. Find out in this article how to do it easily!

December 9, 2024

Creating an animated list with CSS

Let's find out how to create an animated hover list!

December 9, 2024

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 a hovered with CSS

In this tutorial we'll look at how to create an overlay easily using CSS!

December 9, 2024

Playing with blurs and filters on presentation cards with CSS

Looking for a way to display your latest blog posts or projects in a modern, animated way? These cards will go perfectly with your website! Let's find out how to make them.

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 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

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.