Animating a CSS Gradient Border
Gradient borders are a handy CSS technique, and Chris Coyier's demos from the CSS-Tricks article on the subject show the basics. Stephanie Eckles spread the idea around with a more detailed writeup of the three CSS methods for adding element borders. Bramus Van Damme took that approach and extended it by adding an angle to the gradient — and then animating it.
.border-gradient {
border: 5px solid;
border-image-slice: 1;
border-image-source: linear-gradient(to left, #743ad5, #d53a9d);
}
That animation won't run as written, though. The browser has no way to know that 360deg is an actual angle value rather than an arbitrary string. If it could recognize the value as an angle, it would be able to animate it — so you have to declare that with @property.
div {
--angle: 0deg;
/* … */
border-image: linear-gradient(var(--angle), green, yellow) 1;
animation: 10s rotate linear infinite;
}
@keyframes rotate {
to {
--angle: 360deg;
}
}
Van Damme's article has the working demos. The bigger takeaway is what @property unlocks: as Coyier notes, more support would open up plenty of CSS trickery, such as animating numbers visually. At the time of writing, support was limited to Chrome.



