AI CSS Animations

Top Page Loading Bar

The thin glowing bar that runs along the top of the page while a route loads, the way YouTube and GitHub do it. Swap absolute for fixed to pin it to the viewport.

Also known as: NProgress bar, YouTube loading bar, GitHub loading bar.

HTML

<div class="ldr-top-bar" role="progressbar" aria-label="Page loading"></div>

CSS

.ldr-top-bar {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  position: absolute; /* use fixed to pin it to the viewport */
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: max(3px, calc(var(--s) / 16));
  overflow: hidden;
  background: color-mix(in srgb, var(--ldr-color, #3b82f6) 12%, transparent);
}
.ldr-top-bar::before {
  content: "";
  position: absolute;
  inset: 0;
  width: 30%;
  border-radius: 0 999px 999px 0;
  background: var(--c);
  box-shadow: 0 0 10px var(--c), 0 0 4px var(--c);
  animation: ldr-top-bar-run 1.4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
@keyframes ldr-top-bar-run {
  from { transform: translateX(-100%); }
  to   { transform: translateX(340%); }
}

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