Diagonal rainbow bands stream around a black box like a gaming keyboard's RGB strip. A repeating gradient in a tile sized to its period slides one tile per loop, so the bands never jump.
Also known as: rgb border animation css, animated rainbow border css, gaming rgb border.
<div class="bdr-rainbow-rgb-border">Rainbow RGB</div>
.bdr-rainbow-rgb-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;
--fill: color-mix(in srgb, var(--c) 8%, #09090b);
box-sizing: border-box;
border: 0.25em solid transparent;
background:
linear-gradient(var(--fill), var(--fill)) padding-box,
repeating-linear-gradient(45deg, #ff2d55, #ff9500 1.33em, #ffd60a 2.67em, #34c759 4em, #00aaff 5.33em, #5e5ce6 6.67em, #ff2d55 8em) 0 0 / 11.3137em 11.3137em border-box;
color: #fafafa;
letter-spacing: 0.04em;
animation: bdr-rainbow-rgb-border-stream 3s linear infinite;
}
@keyframes bdr-rainbow-rgb-border-stream {
to { background-position: 0 0, 11.3137em 0; }
}
@media (prefers-reduced-motion: reduce) {
.bdr-rainbow-rgb-border, .bdr-rainbow-rgb-border *, .bdr-rainbow-rgb-border::before, .bdr-rainbow-rgb-border::after, .bdr-rainbow-rgb-border *::before, .bdr-rainbow-rgb-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.