Components

Animated gradient border in CSS: a rotating conic border with @property

Build an animated gradient border in CSS: a rotating conic-gradient driven by @property, the padding-box trick, a glow variant, fallbacks and reduced motion.

· 6 min read

The rotating gradient border is everywhere on product pages right now: a card or a call-to-action button with a thin rim of colour that slowly travels around its edge. Until recently it needed a rotating oversized pseudo-element clipped by overflow: hidden. With @property it is now a single element, a gradient and one keyframe.

This guide builds the border, a soft glow variant, a pill button, a React and Tailwind version, and covers what happens in older browsers, what it costs to render and how to respect reduced motion.

Featured Aurora A card with a rotating rim
A rotating conic border on a card and a button

How the animation is put together

Nothing on the page moves. The only thing that changes is one angle, which sets where the conic gradient starts.

PartPropertyDurationDelayEasing
Card border--angle: 0deg → 360deg4 s, infinite0linear
Card glowsame --angle (inherited)4 s, infinite0linear
Button border--angle: 0deg → 360deg3 s, infinite0linear
Pauseanimation-play-stateinstant0none

The button runs a little faster than the card. On a smaller perimeter the same angular speed looks sluggish, and slightly different speeds keep the two from looking mechanically linked.

Step 1: register the angle

A normal custom property is just a string to the browser. It cannot tween a string, so a keyframe from 0deg to 360deg on an unregistered property flips halfway through instead of turning. @property gives the property a type, and typed properties can be interpolated.

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

@keyframes spin-angle {
  to { --angle: 360deg; }
}

inherits: true lets a child or pseudo-element read the value that is animating on its parent. That is what keeps the glow in step with the border later on. If you only need the border, inherits: false is fine and limits the style updates to the element itself.

Step 2: the padding-box trick

You cannot put a gradient in border-color, and border-image ignores border-radius. The usual way round it is two backgrounds with different painting areas.

.gradient-card {
  border: 2px solid transparent;
  border-radius: 16px;
  background:
    linear-gradient(#1c1f26, #1c1f26) padding-box,
    conic-gradient(from var(--angle), #fb9f3d, #7c5cff 30%, #2dd4bf 55%, #fb9f3d 80%) border-box;
  animation: spin-angle 4s linear infinite;
}

Read the background bottom layer first. The conic gradient fills the whole box including the border area (border-box). The solid layer on top fills only up to the inside edge of the border (padding-box). The transparent border lets the conic layer show through as a rim, and border-radius rounds both layers. The solid layer is written as linear-gradient(#1c1f26, #1c1f26) because only the final background layer may be a plain colour.

Start and end the conic gradient on the same colour (#fb9f3d at 0 and again at 80%, running on to 100%). Otherwise there is a hard seam where the gradient wraps around, and the seam travels round the card as it spins.

This needs a solid card colour. If the card itself must be translucent, use a mask instead: put the conic gradient on a ::before with padding equal to the border width, and mask out its content box with mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0). It is more code, so use it only when you need the transparency.

Step 3: the glow variant

The glow is a blurred copy of the same gradient behind the card. A blurred pseudo-element on the card itself would paint over the card's own background, so put it on a wrapper.

<div class="glow">
  <div class="gradient-card">…</div>
</div>
.glow {
  position: relative;
  isolation: isolate;                 /* keeps z-index: -1 inside the wrapper */
  animation: spin-angle 4s linear infinite;
}

.glow::before {
  content: '';
  position: absolute;
  inset: 6px;
  z-index: -1;
  border-radius: 16px;
  background: conic-gradient(from var(--angle), #fb9f3d, #7c5cff 30%, #2dd4bf 55%, #fb9f3d 80%);
  filter: blur(16px);
  opacity: .55;
}

.glow .gradient-card { animation: none; }   /* inherits --angle from .glow */

The animation now runs once, on the wrapper, and both the glow and the card read the inherited --angle. One animation means they cannot drift apart. Insetting the glow by a few pixels keeps it from looking like a hard halo; the blur spreads it back out past the edges.

The button

The same rule set works on a pill button. Only the radius and the speed change.

.gradient-btn {
  padding: 10px 22px;
  border: 2px solid transparent;
  border-radius: 999px;
  color: #e4e4e7;
  background:
    linear-gradient(#1c1f26, #1c1f26) padding-box,
    conic-gradient(from var(--angle), #fb9f3d, #7c5cff 30%, #2dd4bf 55%, #fb9f3d 80%) border-box;
  animation: spin-angle 3s linear infinite;
}
.gradient-btn:focus-visible { outline: 2px solid #fb9f3d; outline-offset: 3px; }

A popular variation runs the spin only on hover: set animation-play-state: paused by default and running on :hover and :focus-visible. The border then resumes from where it stopped instead of snapping back. If you want to see how other sites wire up hover-only effects like this, the guide to capturing hover animations walks through it.

Easing and speed

Browser support and the fallback

@property is supported in current versions of Chrome, Edge, Safari and Firefox; check caniuse if you need to support older versions. The useful detail is what happens when it is missing. The property is then unregistered, so the keyframes flip --angle discretely from 0deg to 360deg. Those two angles draw the same gradient, so the border stays still. Old browsers get a static gradient border, which is a perfectly good fallback, and you do not need to write anything extra.

The one thing to provide is an initial value for var(--angle). Without registration there is no initial-value, so write var(--angle, 0deg) if you want to be safe, or set --angle: 0deg on the element.

Performance

Animating a custom property used in a background means the browser repaints that element's background on every frame. Unlike transform or opacity, this is main-thread and paint work. For a button and a pricing card it is cheap. A few rules keep it that way:

React and Tailwind

Put the @property rule and keyframes in your global CSS. Tailwind cannot generate those, but it can do the rest with arbitrary values.

/* globals.css */
@property --angle { syntax: '<angle>'; inherits: true; initial-value: 0deg; }
@keyframes spin-angle { to { --angle: 360deg; } }
export function GradientCard({ children }) {
  return (
    <div
      className="rounded-2xl border-2 border-transparent p-5 text-zinc-200
                 [background:linear-gradient(#1c1f26,#1c1f26)_padding-box,conic-gradient(from_var(--angle),#fb9f3d,#7c5cff_30%,#2dd4bf_55%,#fb9f3d_80%)_border-box]
                 animate-[spin-angle_4s_linear_infinite] motion-reduce:animate-none"
    >
      {children}
    </div>
  );
}

Underscores stand in for spaces inside Tailwind's arbitrary values. Without Tailwind, the same component is a className="gradient-card" pointing at the CSS from step 2.

Reduced motion

A spinning rim is decorative, so turn it off under prefers-reduced-motion: reduce. The border stays visible as a static gradient at its starting angle. If it runs continuously for more than five seconds, also give users a way to pause it, as the demo's button does.

@media (prefers-reduced-motion: reduce) {
  .glow, .gradient-card, .gradient-btn { animation: none; }
}

Start from one that already works

Gradient borders vary in small details: colour stops, rim width, glow strength, speed. If you have seen one you want to match, you can copy the website animation with Capture Motion, which records the animation while it plays and exports its keyframes, duration and easing as CSS, React or GSAP. Or pick a ready component from the gallery, customize it and export it.

Questions

Why do I need @property to animate a gradient border?

Browsers cannot interpolate an unregistered custom property, so a keyframe change from 0deg to 360deg jumps instead of turning. Registering --angle with the <angle> syntax tells the browser how to tween it smoothly.

What happens in browsers without @property support?

The keyframes flip --angle discretely between 0deg and 360deg, which draw the same gradient, so the border simply stays still. You get a static gradient border with no extra fallback code.

Is an animated gradient border bad for performance?

It repaints the element's background on every frame, so it costs more than a transform animation. Keep it on one or two small elements, avoid large blurred glows, and pause it when it is off-screen.

How do I copy a gradient border animation I saw on another site?

Open the page with the Capture Motion Chrome extension and record the element while it plays. It reads the keyframes, duration and easing of the animated properties and exports CSS, React, GSAP or JSON.