Colors drift slowly back and forth around a light box. The gradient is three times the box size and its background-position eases between two ends, so it needs no @property at all.
Also known as: animated gradient border css, gradient border animation, moving gradient border.
<div class="bdr-animated-gradient-border">Animated gradient</div>
.bdr-animated-gradient-border {
--c: var(--bdr-color, #3b82f6);
font-size: var(--bdr-size, 16px);
position: relative;
display: grid;
place-items: center;
width: 15em;
height: 8.5em;
border-radius: 1em;
font-family: system-ui, sans-serif;
font-weight: 600;
box-sizing: border-box;
border: 0.2em solid transparent;
background:
linear-gradient(#fff, #fff) padding-box,
linear-gradient(115deg, var(--c), color-mix(in oklch, var(--c), #a855f7 70%), color-mix(in oklch, var(--c), #ec4899 80%), color-mix(in oklch, var(--c), #f59e0b 75%), var(--c)) 0 50% / 300% 300% border-box;
color: #111827;
animation: bdr-animated-gradient-border-flow 6s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}
@keyframes bdr-animated-gradient-border-flow {
0%, 100% { background-position: 0 0, 0% 50%; }
50% { background-position: 0 0, 100% 50%; }
}
@media (prefers-reduced-motion: reduce) {
.bdr-animated-gradient-border, .bdr-animated-gradient-border *, .bdr-animated-gradient-border::before, .bdr-animated-gradient-border::after, .bdr-animated-gradient-border *::before, .bdr-animated-gradient-border *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--bdr-color on the element or a parent.
Currently previewing #3b82f6.--bdr-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 16px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.