AI CSS Animations

Animated Gradient Border Loader

A rounded square whose border carries a traveling multi-hue gradient. An oversized conic layer rotates behind a mask that keeps only the edge, so the middle stays clear for an icon.

Also known as: rotating gradient border, rainbow border animation, glowing border loader.

HTML

<div class="ldr-gradient-border" role="status" aria-label="Loading"><span></span></div>

CSS

.ldr-gradient-border {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  width: calc(var(--s) * 0.92);
  height: calc(var(--s) * 0.92);
  filter: drop-shadow(0 0 calc(var(--s) / 10) color-mix(in srgb, var(--ldr-color, #3b82f6) 45%, transparent));
}
.ldr-gradient-border span {
  position: relative;
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: calc(var(--s) / 11);
  border-radius: calc(var(--s) / 4);
  overflow: hidden;
  background: color-mix(in srgb, var(--ldr-color, #3b82f6) 14%, transparent);
  -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);
}
.ldr-gradient-border span::before {
  content: "";
  position: absolute;
  inset: -30%;
  background: conic-gradient(from 0deg, transparent 0 30%, oklch(from var(--c) l c calc(h - 60)) 55%, var(--c) 78%, oklch(from var(--c) l c calc(h + 60)) 100%);
  animation: ldr-gradient-border-spin 1.8s linear infinite;
}
@keyframes ldr-gradient-border-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .ldr-gradient-border, .ldr-gradient-border *, .ldr-gradient-border::before, .ldr-gradient-border::after, .ldr-gradient-border *::before, .ldr-gradient-border *::after {
    animation-duration: 3s;
  }
}

Tailwind CSS version

The same loader using only Tailwind's built-in animation utilities. No custom keyframes or config needed.

<div class="h-11 w-11 drop-shadow-[0_0_5px_rgba(59,130,246,0.45)]" role="status" aria-label="Loading">
  <div class="relative h-full w-full overflow-hidden rounded-xl bg-blue-500/15 p-1 [mask:linear-gradient(#000_0_0)_content-box_exclude,linear-gradient(#000_0_0)]">
    <div class="absolute -inset-[30%] animate-spin bg-[conic-gradient(transparent_0_30%,#06b6d4_55%,#3b82f6_78%,#d946ef_100%)] [animation-duration:1.8s]"></div>
  </div>
</div>

Customizing this loader

  • Color: set --ldr-color on the element or a parent. Currently previewing #3b82f6.
  • Size: set --ldr-size. Every dimension in the snippet is derived from it. Currently previewing 64px.
  • Speed: change the duration on the animation shorthand. Delays on the children are relative, so they keep their rhythm.
  • Accessibility: the root carries role="status" and an aria-label so screen readers announce the wait. The reduced-motion rule at the end slows the animation for users who asked for less motion.

Similar loaders