# scroll()

> The `scroll()` CSS function creates an anonymous scroll progress timeline for an animation.

## How do I create a scroll progress animation in CSS?

The function used with `animation-timeline` that ties animation progress to the scroll position of a scroll container. Often used for reading progress bars and parallax effects.

- Topic: Animations
- Type: function
- Browser support: Chrome 115+, Chrome Android 115+, Edge 115+, Firefox 159+, Firefox Android 159+, Safari 26+, Safari iOS 26+

## Example

Wrong:

```css
.progress-bar {
  animation: grow linear;
  animation-timeline: scroll(self);
}
```

Right:

```css
.progress-bar {
  transform-origin: left;
  animation: grow linear;
  animation-timeline: scroll(root);
}
@keyframes grow {
  from { transform: scaleX(0); }
}
```

The bar itself doesn't scroll, so 'self' never moves it; 'root' follows the page scroll.

## Common mistakes

- The animation never moves because the chosen scroller isn't scrollable.

## Key points

- The scroller ('nearest', 'root', 'self') and axis match the element that really scrolls.
- `animation-timeline: scroll()` is declared after the `animation` shorthand.
- The effect is inside `@supports`, and the page works without it.
- Motion is removed or reduced inside `@media (prefers-reduced-motion: reduce)`.

## Interview questions

### What are the default arguments of scroll()?

`scroll()` uses the 'nearest' ancestor scroll container and the 'block' axis.

### Should I use scroll() or view()?

Use `scroll()` when progress follows how far a container is scrolled. Use `view()` when it follows one element moving through the scrollport.

## Related cards

- [animation-timeline](https://wonderium.dev/css/animation-timeline.md)
- [view()](https://wonderium.dev/css/view-function.md)
- [animation-range](https://wonderium.dev/css/animation-range.md)
- [overflow](https://wonderium.dev/css/overflow.md)
- [@supports](https://wonderium.dev/css/supports.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/scroll-function
- Last updated: 2026-11-25
