AI CSS Animations

Video Buffering Progress Bar

A video scrubber: the buffered range jumps ahead in chunks while the played range and its knob follow at a steady speed, stalling whenever they catch up. Good for media and download UIs.

Also known as: video player progress bar, buffer progress bar, youtube style buffering bar.

HTML

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

CSS

.ldr-buffering-progress-bar {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  --w: calc(var(--s) * 6);
  position: relative;
  width: var(--w);
  height: calc(var(--s) / 10);
  border-radius: var(--s);
  background: color-mix(in srgb, var(--ldr-color, #3b82f6) 16%, transparent);
}
.ldr-buffering-progress-bar::before,
.ldr-buffering-progress-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  transform-origin: left;
}
.ldr-buffering-progress-bar::before {
  background: color-mix(in srgb, var(--ldr-color, #3b82f6) 36%, transparent);
  animation: ldr-buffering-progress-bar-buffer 6s infinite;
}
.ldr-buffering-progress-bar::after {
  background: var(--c);
  animation: ldr-buffering-progress-bar-play 6s linear infinite;
}
.ldr-buffering-progress-bar span {
  position: absolute;
  top: 50%;
  left: calc(var(--s) / -7);
  width: calc(var(--s) / 3.5);
  height: calc(var(--s) / 3.5);
  margin-top: calc(var(--s) / -7);
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 calc(var(--s) / 14) color-mix(in srgb, var(--ldr-color, #3b82f6) 22%, transparent);
  animation: ldr-buffering-progress-bar-knob 6s linear infinite;
}
@keyframes ldr-buffering-progress-bar-buffer {
  0%        { transform: scaleX(0.04); animation-timing-function: cubic-bezier(0.2, 0.7, 0.3, 1); }
  4%, 24%   { transform: scaleX(0.32); animation-timing-function: cubic-bezier(0.2, 0.7, 0.3, 1); }
  28%, 44%  { transform: scaleX(0.58); animation-timing-function: cubic-bezier(0.2, 0.7, 0.3, 1); }
  49%, 66%  { transform: scaleX(0.86); animation-timing-function: cubic-bezier(0.2, 0.7, 0.3, 1); }
  69%, 92%  { transform: scaleX(1); opacity: 1; }
  100%      { transform: scaleX(1); opacity: 0; }
}
@keyframes ldr-buffering-progress-bar-play {
  0%        { transform: scaleX(0); }
  18%, 26%  { transform: scaleX(0.3); }
  41%, 47%  { transform: scaleX(0.55); }
  64%, 68%  { transform: scaleX(0.83); }
  78%, 92%  { transform: scaleX(1); opacity: 1; }
  100%      { transform: scaleX(1); opacity: 0; }
}
@keyframes ldr-buffering-progress-bar-knob {
  0%        { transform: translateX(0); }
  18%, 26%  { transform: translateX(calc(var(--w) * 0.3)) scale(1.2); }
  41%, 47%  { transform: translateX(calc(var(--w) * 0.55)) scale(1.2); }
  64%, 68%  { transform: translateX(calc(var(--w) * 0.83)) scale(1.2); }
  78%, 92%  { transform: translateX(var(--w)); opacity: 1; }
  100%      { transform: translateX(var(--w)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ldr-buffering-progress-bar, .ldr-buffering-progress-bar *, .ldr-buffering-progress-bar::before, .ldr-buffering-progress-bar::after, .ldr-buffering-progress-bar *::before, .ldr-buffering-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