A dark button with an RGB border that flows sideways like gaming gear, and a blurred rainbow glowing under it. The border is a second background clipped to border-box, moved one tile per loop.
Also known as: rgb button css, rainbow button css, gaming rgb border.
<button class="btn-rainbow-border" type="button"><span class="btn-rainbow-border-face">Launch app</span></button>
.btn-rainbow-border {
--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;
--rgb: linear-gradient(90deg, #ff3d6e, #ff9f1c, #ffe14d, #3ddc84, #2ec5ff, #7c5cff, #ff3d6e);
position: relative;
isolation: isolate;
padding: 0;
border-radius: 0.75em;
background: transparent;
color: #fff;
transition: transform 0.2s ease;}
.btn-rainbow-border::before {
content: "";
position: absolute;
top: 45%;
right: 10%;
bottom: -0.3em;
left: 10%;
z-index: -1;
background: var(--rgb) 0 0 / 14em 100%;
filter: blur(0.8em);
opacity: 0.7;
animation: btn-rainbow-border-glow 3s linear infinite;
transition: opacity 0.3s ease;
}
.btn-rainbow-border-face {
display: block;
padding: 0.8em 1.8em;
border: 2px solid transparent;
border-radius: inherit;
background:
linear-gradient(color-mix(in srgb, var(--c) 16%, #0c0f16), color-mix(in srgb, var(--c) 16%, #0c0f16)) padding-box,
var(--rgb) 0 0 / 14em 100% border-box;
animation: btn-rainbow-border-flow 3s linear infinite;
}
.btn-rainbow-border:is(:hover, :focus-visible)::before { opacity: 1; }
.btn-rainbow-border:active { transform: scale(0.97); }
@keyframes btn-rainbow-border-flow {
to { background-position: 0 0, 14em 0; }
}
@keyframes btn-rainbow-border-glow {
to { background-position: 14em 0; }
}
@media (prefers-reduced-motion: reduce) {
.btn-rainbow-border, .btn-rainbow-border *, .btn-rainbow-border::before, .btn-rainbow-border::after, .btn-rainbow-border *::before, .btn-rainbow-border *::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.