GLITCH LAB v1.0 ezolab.dev / lab instrument SYS: READY ✦ Holiday cards

Lab/ Guides/ Technique

Animated Gradient Borders with CSS @property and conic-gradient

Build a rotating gradient border that respects border-radius in pure CSS using @property --angle and conic-gradient, plus transparent glass borders with mask-composite.

/#animation/#neon

Guide // TechniqueLive demos inside
Contents [8]
  1. The quick answer
  2. Why border-image and normal CSS variables fail
  3. Three styles from the exact same CSS
  4. Keeping the center transparent (mask-composite: exclude)
  5. Pause on hover and control speed with variables
  6. Gotchas & browser support
  7. Accessibility
  8. FAQ

A glowing gradient border that travels around a rounded card used to mean either SVG hacks, clipped oversized rotating squares, or JavaScript. With CSS @property and conic-gradient(), it takes a few lines of pure CSS — and it follows any border-radius cleanly.

Here is how the technique works, three visual styles you can copy right away (beam, neon, and soft aura), and how to keep the inside of the card transparent with mask-composite: exclude.

The quick answer

Register an <angle> custom property with @property, give the card a transparent border, and paint two backgrounds: a solid fill that stops at the border (padding-box) and a conic-gradient() that continues under it (border-box). Then rotate --angle from 0deg to 360deg:

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

.card {
  border: 2px solid transparent;   /* border thickness */
  border-radius: 16px;
  background:
    linear-gradient(#101219 0 0) padding-box,   /* the card */
    conic-gradient(                             /* the border */
      from var(--angle, 0deg),
      #23262f 65%,
      #00f5d4 85%,
      #7b61ff 95%,
      #23262f 100%
    ) border-box;
  animation: spin 3.2s linear infinite;
}

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

The fill covers everything inside the border, so the gradient only shows in the 2 px around it. No pseudo-element needed.

Live example — one rotating beam tracing a rounded card:

Rotating gradient beam border using @property --angle and conic-gradient()

Why border-image and normal CSS variables fail

Three traps are easy to fall into on the first try:

  1. border-image ignores border-radius. As soon as you apply a gradient to border-image, your rounded corners snap back to sharp 90-degree rectangles. That is why rounded gradient borders use background layers or a mask instead.
  2. Normal custom properties cannot interpolate. If you animate --angle inside @keyframes without @property, the browser treats --angle as an opaque string. Instead of rotating smoothly, it snaps abruptly at 50%. Registering syntax: "<angle>" tells the browser the variable is a real angle it can interpolate on every frame.
  3. z-index: -1 does not go behind its own card. A popular version puts the gradient on ::before with z-index: -1 and gives the card z-index: 0. But z-index: 0 on a positioned card creates a stacking context, and a stacking context paints its own background first. The gradient lands on top of the fill, behind the text, and covers the whole card.

Three styles from the exact same CSS

Because the motion lives in --angle, changing the conic-gradient color stops completely changes the mood — no new keyframes needed:

  • Subtle beam: a quiet dark border with a short bright tail. Works great on dark SaaS cards and pricing tiers.
  • Full spectrum: evenly spaced colors where the first and last color match so there is no seam.
  • Neon glow aura: add a blurred copy of the gradient on ::after with z-index: -1. Put isolation: isolate on a wrapper and leave z-index off the card itself, so the glow stays behind its fill.
Left: subtle beam. Middle: seamless rainbow. Right: blurred neon aura (::after)

Want to tune the glow, speed, thickness, and dual neon colors live? Open the full Neon Border playground:

[FX_08] Pure CSSNeon BorderCSS neon glow border on a button: two highlights run around the tube, and now and then it flickers out and ignites again. Pure CSS, any text.Tweak it live & copy the code →

Keeping the center transparent (mask-composite: exclude)

The two-background trick needs an opaque fill: that is what hides the middle of the gradient. If your card is translucent (glassmorphism) and should show what is behind it, put the gradient on a ::before and cut out its interior with CSS masks. The card needs position: relative:

.glass-border::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 2px; /* border thickness */
  background: conic-gradient(from var(--angle, 0deg), #00f5d4, #7b61ff, #ff2a85, #00f5d4);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  pointer-events: none;
  animation: spin 4s linear infinite;
}

The mask draws two solid shapes — the full border box and the inner content-box — and subtracts the inner one (exclude / xor). Only the 2 px ring survives:

Transparent glass card over a gradient backdrop — only the 2 px border ring is painted

Pause on hover and control speed with variables

Keep the duration in a custom property (--speed: 3s) so you can reuse one class across buttons, badges, and cards. Adding animation-play-state: paused on :hover gives a tactile freeze when someone points at a button:

Hover the button — the beam freezes in place instead of snapping back to 0deg

Notice that @property is useful far beyond borders — we use the same rule to drive time clocks and typing progress in Chromatic Wave and Typewriter:

[FX_04] CSS + JSTypewriterCSS typewriter effect with @property: letters slide in one by one, the freshest glows hot, then the line erases and types again.Tweak it live & copy the code →

Gotchas & browser support

  • Keep the border transparent. With a solid border-color, the border is painted over the gradient and hides it.
  • Avoid stacking context bugs. The blurred aura needs its stacking context on a wrapper. z-index: 0, isolation, transform, filter or opacity below 1 on the card creates one there instead, and the glow jumps in front of the fill.
  • Browser support. @property and conic-gradient() work in Chrome/Edge 85+, Safari 16.4+, and Firefox 128+. Keep the 0deg fallback in var(--angle, 0deg). Without @property there is no initial value, so with plain var(--angle) the background disappears for half of every loop. With the fallback, browsers that do not know @property show a still gradient.
  • Keep blur() modest. A huge blurred ::after on 20 cards at once can tax mobile GPUs. Use the ::after glow on hero cards or buttons, and the sharp 2 px ring on dense grids.

Accessibility

Always freeze the spinning border when the user prefers reduced motion — keeping the static gradient frame intact so the UI still looks finished:

@media (prefers-reduced-motion: reduce) {
  .card,
  .box,
  .box::after,
  .btn,
  .glass::before,
  .glass-border::before {
    animation: none;
  }
}

FAQ

Why does my CSS conic-gradient border not animate?

Browsers cannot interpolate an unregistered CSS custom property. You must declare @property --angle { syntax: "<angle>"; initial-value: 0deg; inherits: false; } in your stylesheet. Do not nest it inside a selector: there the rule is ignored.

How do I make an animated gradient border with border-radius?

Do not use border-image — it ignores border-radius. Instead, set a transparent border and use two backgrounds: the fill in padding-box and the gradient in border-box. Use a pseudo-element with mask-composite: exclude when the card center needs to stay transparent.

Does @property work inside Tailwind or React?

Yes. Put the @property --angle rule once in your global CSS file, and reference var(--angle) from any component or utility class.