AI CSS Animations

Gradient Progress Bar

A fill that slides in, holds, then sweeps off while a multi-hue gradient flows through it. The hues are rotated from your accent with relative oklch colors, with a color-mix fallback.

Also known as: animated gradient loading bar, rainbow progress bar, colorful progress bar.

HTML

<div class="ldr-gradient-progress-bar" role="progressbar" aria-label="Loading"><span></span></div>

CSS

.ldr-gradient-progress-bar {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  --w: calc(var(--s) * 6);
  width: var(--w);
  height: calc(var(--s) / 5);
  border-radius: var(--s);
  background: color-mix(in srgb, var(--ldr-color, #3b82f6) 14%, transparent);
  overflow: hidden;
}
.ldr-gradient-progress-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background-image: linear-gradient(90deg, var(--c), oklch(from var(--c) l c calc(h + 70)), oklch(from var(--c) l c calc(h + 140)), oklch(from var(--c) l c calc(h + 70)), var(--c));
  background-size: var(--w) 100%;
  animation:
    ldr-gradient-progress-bar-flow 1.4s linear infinite,
    ldr-gradient-progress-bar-run 3.2s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
@supports not (color: oklch(from red l c h)) {
  .ldr-gradient-progress-bar span {
    background-image: linear-gradient(90deg, var(--c), color-mix(in oklch, var(--c), #ec4899), color-mix(in oklch, var(--c), #f59e0b), color-mix(in oklch, var(--c), #ec4899), var(--c));
  }
}
@keyframes ldr-gradient-progress-bar-flow {
  to { background-position: var(--w) 0; }
}
@keyframes ldr-gradient-progress-bar-run {
  0%       { transform: translateX(-100%); }
  55%, 72% { transform: translateX(0); }
  100%     { transform: translateX(100%); }
}

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

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