CSS Animated Rotating Gradient Background
A rotating gradient in pure CSS: two see-through linear gradients slowly spinning in opposite directions, powered by @property. Pick colors and speed.
.bg-rotating-gradient {
--bg: #880088;
--c1: #cc3f47;
--c2: #223b8c;
--speed: 10s;
--spin: 0deg;
background-color: var(--bg);
background-image:
linear-gradient(var(--spin), color-mix(in srgb, var(--c1) 80%, transparent), transparent 70%),
linear-gradient(calc(180deg - var(--spin)), color-mix(in srgb, var(--c2) 80%, transparent), transparent 70%);
animation: bg-rotating-gradient var(--speed) linear infinite;
}
@property --spin {
syntax: "<angle>";
inherits: false;
initial-value: 0deg;
}
@keyframes bg-rotating-gradient {
to { --spin: 360deg; }
}
@media (prefers-reduced-motion: reduce) {
.bg-rotating-gradient { animation: none; }
}<div class="
[--bg:#880088]
[--c1:#cc3f47]
[--c2:#223b8c]
[--speed:10s]
[--spin:0deg]
[background-color:var(--bg)]
[background-image:linear-gradient(var(--spin),_color-mix(in_srgb,_var(--c1)_80%,_transparent),_transparent_70%),_linear-gradient(calc(180deg_-_var(--spin)),_color-mix(in_srgb,_var(--c2)_80%,_transparent),_transparent_70%)]
[animation:bg-rotating-gradient_var(--speed)_linear_infinite]
"></div><!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rotating Gradient — CSS background</title>
<style>
html, body { height: 100%; margin: 0; }
.bg-rotating-gradient {
--bg: #880088;
--c1: #cc3f47;
--c2: #223b8c;
--speed: 10s;
--spin: 0deg;
background-color: var(--bg);
background-image:
linear-gradient(var(--spin), color-mix(in srgb, var(--c1) 80%, transparent), transparent 70%),
linear-gradient(calc(180deg - var(--spin)), color-mix(in srgb, var(--c2) 80%, transparent), transparent 70%);
animation: bg-rotating-gradient var(--speed) linear infinite;
}
@property --spin {
syntax: "<angle>";
inherits: false;
initial-value: 0deg;
}
@keyframes bg-rotating-gradient {
to { --spin: 360deg; }
}
@media (prefers-reduced-motion: reduce) {
.bg-rotating-gradient { animation: none; }
}
</style>
</head>
<body class="bg-rotating-gradient"></body>
</html>How this rotating gradient works
CSS can’t normally animate a gradient’s angle, because a custom property like --spin is just text to the browser. The @property rule fixes that. It registers --spin as an <angle>, so the browser knows how to tween it from 0deg to 360deg, and the @keyframes rule does exactly that.
Two see-through linear-gradient() layers use the angle. The first runs at var(--spin). The second runs at calc(180deg - var(--spin)), which turns the other way. Each starts at 80% of its color and fades out by 70%, so they keep crossing and mixing over the purple base as they turn. --speed sets how long one full turn takes.
When you paste it, keep the @property, @keyframes and reduced-motion rules from the CSS tab. The Tailwind tab covers the main rule only. Browsers without @property show a still gradient.
Use it for hero sections, splash screens and music or event pages.