Each side of the box wears its own color, and every couple of seconds the colors hop one side clockwise. Plain border-color with four values animates here, so it works in every browser.
Also known as: multi color border css, four color border css, different color border each side.
<div class="bdr-multicolor-border">Multicolor</div>
.bdr-multicolor-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.22em solid;
border-color: var(--c) #ef4444 #facc15 #22c55e;
background: color-mix(in srgb, var(--c) 6%, transparent);
animation: bdr-multicolor-border-hop 6s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
@keyframes bdr-multicolor-border-hop {
0%, 18% { border-color: var(--c) #ef4444 #facc15 #22c55e; }
25%, 43% { border-color: #22c55e var(--c) #ef4444 #facc15; }
50%, 68% { border-color: #facc15 #22c55e var(--c) #ef4444; }
75%, 93% { border-color: #ef4444 #facc15 #22c55e var(--c); }
100% { border-color: var(--c) #ef4444 #facc15 #22c55e; }
}
@media (prefers-reduced-motion: reduce) {
.bdr-multicolor-border, .bdr-multicolor-border *, .bdr-multicolor-border::before, .bdr-multicolor-border::after, .bdr-multicolor-border *::before, .bdr-multicolor-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.