DEV Community

Jordi
Jordi

Posted on

10 1

Create CSS Gradient Animations Effortlessly 🌌

Here's a preview of what we'll make 👇

1. Create a gradient

I'll save mine in a variable for easy reuse.

:root {
  --main-gradient: linear-gradient(-66deg, #15162a, #000, #291a33, #000, #381a2c, #000, #121e42);
}
Enter fullscreen mode Exit fullscreen mode

2. Create a container div and add the background

We use background-size to zoom into the gradient.

.container {
  background: var(--main-gradient);
  background-size: 400%;
}
Enter fullscreen mode Exit fullscreen mode

3. Create the animation

This is a basic animation that changes the background-position. Since we zoomed into the gradient it will look like it's moving.

@keyframes gradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 00% 50%;
  }
}
Enter fullscreen mode Exit fullscreen mode

4. Add the animation to our container!

.container {
  background: var(--main-gradient);
  background-size: 400%;
  animation: gradient 8s ease infinite;
}
Enter fullscreen mode Exit fullscreen mode

You can check the codepen here

And that's it!

Follow me on twitter for more!

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay