Animated Gradients with CSS @property: No JavaScript Needed

September 30, 2026  |  11 min read  |  CSS

By Syed · Frontend Engineer & Creator of UITweak

For years, animating a gradient meant hacks: sliding background-position on an oversized gradient, or reaching for JavaScript. Both felt wrong because they were. The clean solution is @property, which lets you register a custom property with a type so the browser can interpolate it smoothly. With three lines of registration, gradients become animatable in pure CSS.

Shortcut: prototype gradient and keyframe animations visually in our free CSS Animation Generator, then add @property registration for the smooth gradient motion shown below.

1. Why Gradients Refused to Animate

A gradient is technically a background-image, and images are not interpolable values. You cannot transition from one gradient to another the way you transition a color or a length. Worse, an unregistered custom property like --angle: 0deg is treated as an untyped token stream, so keyframes using it jump discretely instead of animating. That is the whole problem @property solves: it gives your variable a type.

2. Registering a Property in Three Lines

Registration tells the browser three things: the value type, the starting value, and whether it inherits. Once registered, the property animates like any built-in CSS property:

@property --angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

@property --hue {
  syntax: "<number>";
  initial-value: 250;
  inherits: false;
}

The syntax descriptor accepts types like "<angle>", "<number>", "<color>", "<length>", and "<percentage>". Registration is supported in all modern browsers, so for most audiences this is production-ready today.

3. Recipe: A Rotating Conic Glow

The signature effect: a conic gradient that rotates forever. Perfect for avatar rings, loader glows, and card spotlights:

.glow {
  --angle: 0deg;
  background: conic-gradient(
    from var(--angle),
    oklch(70% 0.16 250),
    oklch(68% 0.18 320),
    oklch(70% 0.16 250)
  );
  animation: rotate-gradient 4s linear infinite;
}
@keyframes rotate-gradient {
  to { --angle: 360deg; }
}

Because --angle is registered as an <angle>, the browser interpolates 0deg to 360deg smoothly. Without registration, this same code would snap from start to end with no motion at all. That contrast is the entire reason @property exists.

4. Recipe: A Hue-Shifting Linear Gradient

Instead of rotating, drift the colors themselves through the spectrum by animating a registered number used as a hue:

.hero-text {
  --hue: 250;
  background: linear-gradient(
    120deg,
    oklch(70% 0.16 var(--hue)),
    oklch(68% 0.18 calc(var(--hue) + 60))
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: hue-drift 8s ease-in-out infinite alternate;
}
@keyframes hue-drift {
  to { --hue: 340; }
}

Note the calc(var(--hue) + 60): the second stop stays 60 degrees ahead of the first, so the gradient keeps its character while the whole palette slides. This is a far richer effect than the old background-position slide trick, and it costs nothing extra.

5. Recipe: The Animated Gradient Border

The popular "border beam" effect is a registered angle combined with the padding-box/border-box background trick:

.card {
  --angle: 0deg;
  border: 2px solid transparent;
  border-radius: 1rem;
  background:
    linear-gradient(#0f172a, #0f172a) padding-box,
    conic-gradient(from var(--angle), oklch(70% 0.16 250), oklch(68% 0.18 320), oklch(70% 0.16 250)) border-box;
  animation: rotate-gradient 5s linear infinite;
}

The solid layer covers the inside (clipped to the padding box) while the animated conic gradient shows only through the 2px border. One element, no pseudo-elements, no extra markup.

6. Fallbacks: Graceful by Default

The good news: @property degrades gracefully without any extra code. A browser that does not understand registration simply ignores the @property block and renders the gradient with the initial-value statically. Your design still looks correct, it just does not move. If you want an explicit check, gate the animation like this:

/* Static gradient everywhere */
.badge {
  background: conic-gradient(oklch(70% 0.16 250), oklch(68% 0.18 320), oklch(70% 0.16 250));
}

/* Motion only where @property is supported */
@supports (syntax: "<angle>") {
  .badge {
    --angle: 0deg;
    background: conic-gradient(from var(--angle), oklch(70% 0.16 250), oklch(68% 0.18 320), oklch(70% 0.16 250));
    animation: rotate-gradient 4s linear infinite;
  }
}

7. Respect Reduced Motion

Animated gradients are ambient motion, which is exactly what the prefers-reduced-motion setting exists for. One block covers every recipe on the page:

@media (prefers-reduced-motion: reduce) {
  .glow, .hero-text, .card, .badge {
    animation: none;
  }
}

8. Recipe: Animated Gradient Text

One of the most searched uses of this technique: text filled with a moving gradient. The trick is background-clip: text combined with a shifting background position:

.gradient-text {
  background: linear-gradient(90deg, #6366f1, #a855f7, #ec4899, #6366f1);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: text-shift 6s linear infinite;
}
@keyframes text-shift {
  to { background-position: 300% 0; }
}

Control the speed with the duration: 6s is calm, 3s is energetic. Keep color: transparent with a solid-color fallback for browsers without background-clip: text support.

9. Where This Shines (and Where It Does Not)

  • Great for: loaders, avatar rings, CTA button sheens, card borders, section dividers, and ambient hero backgrounds.
  • Skip it for: large full-screen animated backgrounds on low-end phones. A rotating conic gradient repainted every frame is heavier than the transform-based drift we used in our mesh gradient guide. Use @property animation on contained elements, transform animation on full-bleed ones.
  • Keep durations slow: 4 to 10 seconds per cycle. Fast-spinning gradients read as alarming, not premium.

Pair this technique with the CSS Animation Generator to prototype timing and easing visually, then drop in your registered properties for the gradient motion itself.

@property browser support in plain terms

@property shipped in Chrome and Edge 85 back in 2020, Safari 16.4 in 2023, and Firefox 128 in 2024. That makes it Baseline widely available, which is the practical way of saying you can use it without a polyfill for almost any audience. The one gap that still bites: Safari versions before 16.4. Those are iOS 15 devices and older macOS installs that never updated. On those browsers your @property block is ignored and the gradient renders statically with the initial value. That is fine degradation for decoration, but if the animation carries meaning, a loading state or a progress cue, keep the @supports guard and provide a non-motion signal too. I treat @property like custom properties in 2018: safe by default, guarded where it matters.

The registered-color trick: animating stops themselves

Angle and hue get the attention, but the most useful registration in practice is <color>. Register two color stops and you can morph a gradient from one brand palette to another without touching the markup.

@property --stop-a {
  syntax: "<color>";
  initial-value: #6366f1;
  inherits: false;
}
@property --stop-b {
  syntax: "<color>";
  initial-value: #a855f7;
  inherits: false;
}

.promo {
  background: linear-gradient(120deg, var(--stop-a), var(--stop-b));
  animation: rebrand 6s ease-in-out infinite alternate;
}
@keyframes rebrand {
  to { --stop-a: #0ea5e9; --stop-b: #22d3ee; }
}

I prefer this over hue rotation whenever the design has fixed brand colors. Hue drift slides through every color in between, including muddy ones. Registered colors interpolate directly from A to B, so the midpoint is always a blend of your two chosen colors. Nothing unexpected shows up mid-animation.

The global namespace gotcha

@property registration is document-global. There is one --angle for the whole page, not one per component. If two unrelated components each register --angle with different syntax, the page has a conflict, and the symptom is bizarre: one component's animation starts driving the other's gradient. The fix is boring and effective: prefix every registered property with the component or feature name. --hero-angle, --badge-hue, --card-stop-a. Register each property exactly once, at the top level of your stylesheet, next to your other global tokens. A @property rule nested inside a selector is invalid and gets dropped, so keep them top-level like @font-face. In practice I keep all @property registrations in one place, the design-token file, so a name collision is visible the moment it is written.

FAQ

How can I create an animated gradient background?

Register the animated value with @property, then animate it in@keyframes. For angle-based motion (rotating conic gradients), register --angle as <angle>. For position-based motion, animate background-position on an oversized gradient. Both patterns are covered with copy-paste recipes in sections 3 and 4 above.

How do I control the speed of a CSS gradient animation?

Change the animation-duration: shorter is faster. A 4s cycle feels calm and premium, 10s is barely noticeable ambient motion, and anything under 2s starts to feel alarming. Keep the timing function linear for seamless loops.

Can I animate a gradient on hover only?

Yes. Set animation-play-state: paused by default and switch to running on :hover. This gives you animated gradient buttons and cards that sit still until the user interacts, which is calmer for the page and cheaper on battery.

Why is my animated gradient choppy on mobile?

Animating @property angles repaints every frame. On low-end phones, prefer transform-based motion (moving an oversized gradient layer with translate) over repainting the gradient itself. Also keep animated gradients contained; full-screen repaints are the most expensive kind.

Share this guide