A new color paints itself clockwise over the old one, then the next color does the same, round after round. A conic stop sweeps on an @property percentage while two registered colors hand over.
Also known as: border color transition css, paint border animation, border wipe animation css.
<div class="bdr-color-wipe-border">Color wipe</div>
@property --bdr-color-wipe-border-p {
syntax: "<percentage>";
inherits: false;
initial-value: 0%;
}
@property --bdr-color-wipe-border-from {
syntax: "<color>";
inherits: false;
initial-value: transparent;
}
@property --bdr-color-wipe-border-to {
syntax: "<color>";
inherits: false;
initial-value: transparent;
}
.bdr-color-wipe-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;
--one: var(--c);
--two: color-mix(in oklch, var(--c), #ec4899 85%);
--three: color-mix(in oklch, var(--c), #f59e0b 80%);
box-sizing: border-box;
border: 0.24em solid transparent;
background:
linear-gradient(#fff, #fff) padding-box,
conic-gradient(var(--bdr-color-wipe-border-to) calc(var(--bdr-color-wipe-border-p) - 3%), var(--bdr-color-wipe-border-from) var(--bdr-color-wipe-border-p)) border-box;
color: #111827;
animation: bdr-color-wipe-border-paint 4.5s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
@keyframes bdr-color-wipe-border-paint {
0% { --bdr-color-wipe-border-p: 0%; --bdr-color-wipe-border-from: var(--one); --bdr-color-wipe-border-to: var(--two); }
33.3% { --bdr-color-wipe-border-p: 103%; --bdr-color-wipe-border-from: var(--one); --bdr-color-wipe-border-to: var(--two); }
33.4% { --bdr-color-wipe-border-p: 0%; --bdr-color-wipe-border-from: var(--two); --bdr-color-wipe-border-to: var(--three); }
66.6% { --bdr-color-wipe-border-p: 103%; --bdr-color-wipe-border-from: var(--two); --bdr-color-wipe-border-to: var(--three); }
66.7% { --bdr-color-wipe-border-p: 0%; --bdr-color-wipe-border-from: var(--three); --bdr-color-wipe-border-to: var(--one); }
100% { --bdr-color-wipe-border-p: 103%; --bdr-color-wipe-border-from: var(--three); --bdr-color-wipe-border-to: var(--one); }
}
@media (prefers-reduced-motion: reduce) {
.bdr-color-wipe-border, .bdr-color-wipe-border *, .bdr-color-wipe-border::before, .bdr-color-wipe-border::after, .bdr-color-wipe-border *::before, .bdr-color-wipe-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.