Two comets of light chase each other around the edge of a quiet outline button. Each is a soft dot moved along the rectangle with translate keyframes, then masked so only the border ring shows it.
Also known as: light traveling around border, border beam css, animated border light button.
<button class="btn-border-beam" type="button"> <span class="btn-border-beam-ring" aria-hidden="true"><i></i><i></i></span> View changelog </button>
.btn-border-beam {
--c: var(--btn-color, #3b82f6);
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5em;
padding: 0.75em 1.6em;
border: 0;
border-radius: 0.6em;
font: 600 var(--btn-size, 18px)/1.1 system-ui, sans-serif;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
--w: 12em;
--h: 3em;
position: relative;
width: var(--w);
height: var(--h);
padding: 0;
border-radius: 0.8em;
background: color-mix(in srgb, var(--c) 8%, transparent);
color: var(--c);
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c) 28%, transparent);
transition: background-color 0.25s ease, transform 0.2s ease;}
.btn-border-beam-ring {
position: absolute;
inset: 0;
padding: 2px;
border-radius: inherit;
-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
-webkit-mask-composite: xor;
mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
pointer-events: none;
}
.btn-border-beam-ring i {
position: absolute;
top: -3em;
left: -3em;
width: 6em;
height: 6em;
background: radial-gradient(closest-side, var(--c) 15%, transparent);
animation: btn-border-beam-orbit 4s linear infinite;
}
.btn-border-beam-ring i:nth-child(2) {
background: radial-gradient(closest-side, color-mix(in srgb, var(--c) 35%, #ec4899) 15%, transparent);
animation-delay: -2s;
}
.btn-border-beam:is(:hover, :focus-visible) { background-color: color-mix(in srgb, var(--c) 14%, transparent); }
.btn-border-beam:active { transform: scale(0.97); }
@keyframes btn-border-beam-orbit {
0%, 100% { transform: translate(0, 0); }
40% { transform: translate(var(--w), 0); }
50% { transform: translate(var(--w), var(--h)); }
90% { transform: translate(0, var(--h)); }
}
@media (prefers-reduced-motion: reduce) {
.btn-border-beam, .btn-border-beam *, .btn-border-beam::before, .btn-border-beam::after, .btn-border-beam *::before, .btn-border-beam *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--btn-color on the element or a parent.
Currently previewing #3b82f6.--btn-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 18px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.