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:
Why border-image and normal CSS variables fail
Three traps are easy to fall into on the first try:
border-imageignoresborder-radius. As soon as you apply a gradient toborder-image, your rounded corners snap back to sharp 90-degree rectangles. That is why rounded gradient borders use background layers or a mask instead.- Normal custom properties cannot interpolate. If you animate
--angleinside@keyframeswithout@property, the browser treats--angleas an opaque string. Instead of rotating smoothly, it snaps abruptly at 50%. Registeringsyntax: "<angle>"tells the browser the variable is a real angle it can interpolate on every frame. z-index: -1does not go behind its own card. A popular version puts the gradient on::beforewithz-index: -1and gives the cardz-index: 0. Butz-index: 0on 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
::afterwithz-index: -1. Putisolation: isolateon a wrapper and leavez-indexoff the card itself, so the glow stays behind its fill.
Want to tune the glow, speed, thickness, and dual neon colors live? Open the full Neon Border playground:
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:
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:
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:
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,filteroropacitybelow 1 on the card creates one there instead, and the glow jumps in front of the fill. - Browser support.
@propertyandconic-gradient()work in Chrome/Edge 85+, Safari 16.4+, and Firefox 128+. Keep the0degfallback invar(--angle, 0deg). Without@propertythere is no initial value, so with plainvar(--angle)the background disappears for half of every loop. With the fallback, browsers that do not know@propertyshow a still gradient. - Keep
blur()modest. A huge blurred::afteron 20 cards at once can tax mobile GPUs. Use the::afterglow 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.