Patch Bandit

The story / The lab

Blueberry · 2026-11-22

CSS animate on scroll without JavaScript

You can make elements CSS animate on scroll using one line of CSS — animation-timeline: view() — so cards glide into place and progress bars fill in sync with your scrollbar, with zero JavaScript and a clean static fallback.

Scroll the little box below and watch CSS do the work by itself.

Snick the raccoon watching a timeline scroll by
Scroll inside this windowpure CSS · zero script

Step 01

No scroll listener

Your browser updates frames directly on its compositor thread instead of firing JavaScript on every scroll pixel.

Step 02

Reversible by default

Scroll forward and the card settles into place; scroll back up and it glides smoothly in reverse.

Step 03

Scoped to any box

Using scroll(nearest) ties a progress bar to an inner scroll window or to the full page.

Step 04

Range controls timing

animation-range: entry 0% cover 32% finishes the glide well before the card reaches the middle of your screen.

Step 05

Plain fallback built in

Browsers without animation-timeline ignore the @supports block and show every card in its finished resting spot.

Scroll inside the demo frame

The progress strip across the top of that frame uses animation-timeline: scroll(nearest), while every card inside glides and extends its mint bar using animation-timeline: view().

If you turn on Reduced Motion in your operating system settings, every card and bar sits quietly in its finished position with zero motion.

Your browser supports animation-timeline: view() — the demo frame is live.

Your browser does not support animation-timeline: view() yet — you are seeing the clean static fallback.

How scroll animation CSS works in three parts

As you scroll down this page, the mint bar along the top of each card below also runs on animation-timeline: view() — no script observer attached.

  • 1. Write normal keyframes

    Start with an ordinary @keyframes block that describes the starting and finished transform. Nothing new to learn in the keyframes themselves.

  • 2. Attach a timeline

    Swap clock time for scroll position with animation-timeline: view() (tracks an element entering the screen) or scroll() (tracks the whole scrollbar).

  • 3. Pick the range

    Set animation-range: entry 0% cover 32% so the move finishes smoothly in the lower third of the screen instead of dragging all the way to the top edge.

Copy the scroll animation CSS

Viewport reveal with animation-timeline: view() (CSS)
@keyframes reveal-up {
  from {
    transform: translateY(24px) scale(0.95);
  }
  to {
    transform: translateY(0) scale(1);
  }
}

/* Only run when the browser supports view() and the visitor allows motion */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .reveal-card {
      animation: reveal-up linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 32%;
    }
  }
}

Reading progress bar with scroll() (CSS)
@keyframes grow-bar {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.progress-bar {
  height: 4px;
  background: #86e3be;
  transform-origin: left center;
}

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: scroll()) {
    .progress-bar {
      animation: grow-bar linear both;
      animation-timeline: scroll(nearest);
    }
  }
}

Browser support: animation-timeline: view() and scroll() work in current Chrome and Edge today. Firefox and Safari are still rolling out support and cleanly ignore the @supports block, displaying the finished static layout with no jump. Tested in Chromium only.

The fine print, in plain words

Why this is free

We're raccoons who think simple things shouldn't cost a monthly fee. We take techniques apart, explain them in plain words, and give them away. The code on this page is MIT licensed: copy it, change it, and share it.

This is one of twelve experiments so far. Our first browser tool (Bandit Codes) is live now, and the rest sit as ideas in the stash.