CSS Spinning Border Button
A dark button with a beam of light that travels around its border, the look used for AI features.
<button class="btn-spin-border">Ask AI</button>
.btn-spin-border {
position: relative;
isolation: isolate;
overflow: hidden;
padding: 14px 34px;
border: 0;
border-radius: 12px;
background: #1e293b;
color: #e2e8f0;
font: 600 16px/1 system-ui, sans-serif;
cursor: pointer;
}
/* A large rotating conic gradient, clipped by the button */
.btn-spin-border::before {
content: "";
position: absolute;
top: 50%;
left: 50%;
z-index: -2;
width: 200%;
aspect-ratio: 1;
background: conic-gradient(#0000 0 65%, #38bdf8, #a78bfa, #0000 95%);
transform: translate(-50%, -50%);
animation: btn-spin-border-rotate 3s linear infinite;
}
/* The inner fill covers everything except a 2px ring */
.btn-spin-border::after {
content: "";
position: absolute;
inset: 2px;
z-index: -1;
border-radius: 10px;
background: #0b1120;
}
.btn-spin-border:focus-visible {
outline: 2px solid #38bdf8;
outline-offset: 3px;
}
@keyframes btn-spin-border-rotate {
to { transform: translate(-50%, -50%) rotate(1turn); }
}
@media (prefers-reduced-motion: reduce) {
.btn-spin-border::before { animation: none; }
}
About this CSS Spinning Border Button
This CSS Spinning Border Button is 49 lines of pure CSS (1.1 KB) with no JavaScript and no dependencies. It uses keyframe animations, transforms, conic gradients and aspect-ratio. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#1e293b#e2e8f0#0000#38bdf8#a78bfa#0b1120
How to use this spinning border button
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.btn-spin-borderclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.