CSS Animated Border Card

A dark card with a gradient border that keeps rotating around its edge.

  • border
  • animated
  • conic
  • rotate
  • gradient
  • dark
HTML
<div class="border-spin">
  <h3>Realtime sync</h3>
  <p>Every change shows up everywhere, instantly.</p>
</div>
CSS
.border-spin {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: 220px;
  padding: 22px;
  border-radius: 16px;
  color: #cbd5e1;
  font: 14px/1.5 system-ui, sans-serif;
}

/* A spinning gradient, larger than the card */
.border-spin::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: -2;
  width: 200%;
  aspect-ratio: 1;
  background: conic-gradient(#22d3ee, #a855f7, #f43f5e, #22d3ee);
  translate: -50% -50%;
  animation: border-spin 4s linear infinite;
}

/* The inner panel covers all but a 2px edge */
.border-spin::after {
  content: "";
  position: absolute;
  inset: 2px;
  z-index: -1;
  border-radius: 14px;
  background: #0f172a;
}

.border-spin h3 {
  margin: 0 0 6px;
  color: #f8fafc;
  font-size: 17px;
}

.border-spin p {
  margin: 0;
}

@keyframes border-spin {
  to { rotate: 1turn; }
}

@media (prefers-reduced-motion: reduce) {
  .border-spin::before { animation: none; }
}

About this CSS Animated Border Card

This CSS Animated Border Card is 52 lines of pure CSS (0.9 KB) with no JavaScript and no dependencies. It uses keyframe animations, conic gradients, aspect-ratio and reduced-motion support. 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:

  • #cbd5e1
  • #22d3ee
  • #a855f7
  • #f43f5e
  • #0f172a
  • #f8fafc

How to use this animated border card

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .border-spin class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in 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.

Feedback