AI CSS Animations

Rotating Gradient Border

The classic animated border: a multi-color conic gradient turns around a rounded box. A registered @property angle drives it, and padding-box plus border-box backgrounds keep the radius clean.

Also known as: rotating border css, spinning gradient border, conic gradient border animation.

Rotating border

HTML

<div class="bdr-rotating-gradient-border">Rotating border</div>

CSS

@property --bdr-rotating-gradient-border-a {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
.bdr-rotating-gradient-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;
  --fill: color-mix(in srgb, var(--c) 10%, #0b0f19);
  box-sizing: border-box;
  border: 0.2em solid transparent;
  background:
    linear-gradient(var(--fill), var(--fill)) padding-box,
    conic-gradient(from var(--bdr-rotating-gradient-border-a), var(--c), color-mix(in oklch, var(--c), #d946ef 70%), color-mix(in oklch, var(--c), #f97316 70%), color-mix(in oklch, var(--c), #22d3ee 70%), var(--c)) border-box;
  color: #f1f5f9;
  animation: bdr-rotating-gradient-border-spin 4s linear infinite;
}
@keyframes bdr-rotating-gradient-border-spin {
  to { --bdr-rotating-gradient-border-a: 360deg; }
}

@media (prefers-reduced-motion: reduce) {
  .bdr-rotating-gradient-border, .bdr-rotating-gradient-border *, .bdr-rotating-gradient-border::before, .bdr-rotating-gradient-border::after, .bdr-rotating-gradient-border *::before, .bdr-rotating-gradient-border *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Tailwind CSS version

The same effect using Tailwind utility classes. No custom CSS or config needed.

<div class="relative grid h-[8.5em] w-[15em] place-items-center overflow-hidden rounded-2xl p-[3px]">
  <div class="absolute inset-[-100%] animate-spin bg-[conic-gradient(#3b82f6,#d946ef,#f97316,#22d3ee,#3b82f6)] [animation-duration:4s]"></div>
  <div class="relative grid h-full w-full place-items-center rounded-[13px] bg-slate-950 font-semibold text-slate-100">Rotating border</div>
</div>

Customizing this snippet

  • Color: set --bdr-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --bdr-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar border animations