CSS scroll-timeline Property

The CSS scroll-timeline property is a shorthand that creates a named scroll progress timeline and specifies the scrolling axis used to control its progress.

It combines scroll-timeline-name and scroll-timeline-axis. A scroll-driven animation can reference the resulting timeline through animation-timeline, allowing animation progress to follow scrolling instead of elapsed time.

scroll-timeline Syntax

The scroll-timeline shorthand accepts a timeline name and an optional scrolling axis. Multiple timeline definitions can be separated by commas.

Basic Syntax

selector {
  scroll-timeline: --timeline-name block;
}

Available Syntax

.container {
  scroll-timeline: none;
}
.container {
  scroll-timeline: --page-scroll;
}
.container {
  scroll-timeline: --page-scroll block;
}
.container {
  scroll-timeline: --horizontal-scroll inline;
}
.container {
  scroll-timeline: --horizontal-scroll x;
}
.container {
  scroll-timeline: --vertical-scroll y;
}

Multiple Timelines

.container {
  scroll-timeline: --vertical-progress block, --horizontal-progress inline;
}

Each comma-separated definition creates a named timeline with its own scrolling axis.

CSS-Wide Keywords

.container {
  scroll-timeline: initial;
}
.container {
  scroll-timeline: inherit;
}
.container {
  scroll-timeline: unset;
}
.container {
  scroll-timeline: revert;
}
.container {
  scroll-timeline: revert-layer;
}

Timeline names use dashed identifiers beginning with two hyphens, such as --reading-progress.

Property Values

Value Description
none Does not establish a named scroll progress timeline for that list entry.
--custom-name Defines a named scroll progress timeline using a dashed identifier.
block Uses the logical block axis. This is the default axis.
inline Uses the logical inline axis.
x Uses the physical horizontal scrolling axis.
y Uses the physical vertical scrolling axis.
initial Resets the shorthand to its initial longhand values.
inherit Inherits the computed longhand values from the parent.
unset Resets the non-inherited longhands to their initial values.
revert Reverts the shorthand according to CSS cascade origin rules.
revert-layer Reverts the shorthand according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Property type Shorthand
Initial value none
Inherited No
Applies to All elements
Computed value Determined by its longhand properties
Animation type Determined by its longhand properties
Percentages Not applicable
Default axis block
Longhand properties scroll-timeline-name, scroll-timeline-axis

Valid Values

.container {
  scroll-timeline: --progress;
}
.container {
  scroll-timeline: --progress block;
}
.container {
  scroll-timeline: --gallery inline;
}
.container {
  scroll-timeline: --horizontal x;
}
.container {
  scroll-timeline: --vertical y;
}
.container {
  scroll-timeline: --one block, --two inline;
}

Invalid Values

.container {
  scroll-timeline: progress;
}
.container {
  scroll-timeline: --progress both;
}
.container {
  scroll-timeline: --progress mandatory;
}
.container {
  scroll-timeline: --progress 50%;
}
.container {
  scroll-timeline: --progress horizontal;
}

The both and mandatory keywords belong to scroll-snap-type, not scroll-timeline. The timeline axis must be block, inline, x, or y.

How It Works

A scroll progress timeline tracks the scroll position of a scroll container along a selected axis. Its progress can drive a CSS animation from its beginning to its end.

Step 1: Create a Scroll Container

.scroll-container {
  height: 300px;
  overflow-y: auto;
}

The container must have a scrollable range along the selected axis for its timeline to produce meaningful progress.

Step 2: Name the Timeline

.scroll-container {
  scroll-timeline: --reading-progress block;
}

This establishes a named scroll progress timeline using the logical block axis.

Step 3: Define an Animation

@keyframes grow-progress {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

Step 4: Connect the Animation

.scroll-container .progress-bar {
  transform-origin: left;
  animation: grow-progress linear both;
  animation-timeline: --reading-progress;
}

The animation follows the named timeline rather than progressing solely according to elapsed time.

Timeline Progress

For a typical scroll container, progress begins at 0% at the start of its scrollable range and reaches 100% at the end. Intermediate scroll positions produce intermediate progress values.

Scrolling Backward

When the user scrolls toward the beginning, the timeline progress decreases. The animation can therefore reverse naturally without separate JavaScript logic.

Inactive Timelines

If the selected axis has no scrollable range, the timeline is inactive. Animations attached to an inactive timeline do not progress normally.

No Automatic Animation

Defining scroll-timeline does not animate anything by itself. An animation must reference the timeline through animation-timeline.

Shorthand and Longhand Properties

The scroll-timeline shorthand sets two longhand properties.

Longhand Property Purpose
scroll-timeline-name Defines one or more names for scroll progress timelines.
scroll-timeline-axis Defines the scrolling axis used by each named timeline.

Shorthand Declaration

.container {
  scroll-timeline: --progress block;
}

Equivalent Longhand Declarations

.container {
  scroll-timeline-name: --progress;
  scroll-timeline-axis: block;
}

Omitting the Axis

.container {
  scroll-timeline: --progress;
}

The omitted axis defaults to block.

Multiple Timelines

.container {
  scroll-timeline: --vertical block, --horizontal inline;
}

This is equivalent to:

.container {
  scroll-timeline-name: --vertical, --horizontal;
  scroll-timeline-axis: block, inline;
}

Resetting Longhand Values

.container {
  scroll-timeline-name: --progress;
  scroll-timeline-axis: inline;
  scroll-timeline: --progress;
}

The final shorthand resets the axis to block. A shorthand declaration resets omitted longhand components to their initial values.

Important Consideration

Use the shorthand for concise definitions and the longhands when timeline names and axes need to be managed separately.

Naming Scroll Timelines

Named scroll timelines use dashed identifiers beginning with two hyphens. These names are referenced by the animation-timeline property.

Basic Timeline Name

.container {
  scroll-timeline: --reading-progress block;
}

Referencing the Name

.progress-bar {
  animation: grow-progress linear both;
  animation-timeline: --reading-progress;
}

Multiple Named Timelines

.container {
  scroll-timeline: --vertical-progress block, --horizontal-progress inline;
}

The two timelines can be referenced independently by different animations.

Case Sensitivity

.container {
  scroll-timeline: --PageProgress;
}
.progress-bar {
  animation-timeline: --pageprogress;
}

These identifiers do not match because custom identifiers are case-sensitive.

Names Are Not Custom Properties

Although both use the -- prefix, a scroll timeline name is not a CSS custom property. It is not assigned or retrieved using var().

Meaningful Names

Choose descriptive names such as --article-progress, --gallery-scroll, or --section-progress to make timeline relationships easier to maintain.

Scrolling Axes

The axis determines which scrolling direction controls the timeline's progress.

Axis Description
block Follows the logical block axis.
inline Follows the logical inline axis.
x Follows the physical horizontal axis.
y Follows the physical vertical axis.

Block-Axis Timeline

.container {
  overflow-y: auto;
  scroll-timeline: --progress block;
}

In horizontal writing, the block axis is vertical.

Inline-Axis Timeline

.container {
  overflow-x: auto;
  scroll-timeline: --progress inline;
}

In horizontal writing, the inline axis is horizontal.

Physical Horizontal Timeline

.container {
  overflow-x: auto;
  scroll-timeline: --progress x;
}

Physical Vertical Timeline

.container {
  overflow-y: auto;
  scroll-timeline: --progress y;
}

Writing Mode Comparison

Writing Mode Block Axis Inline Axis
horizontal-tb Vertical Horizontal
vertical-rl Horizontal Vertical
vertical-lr Horizontal Vertical

Important Consideration

Use logical axes when the timeline should adapt to writing modes. Use physical axes when the scrolling direction should remain horizontal or vertical.

Using animation-timeline

The animation-timeline property connects a CSS animation to a named scroll timeline.

Define the Timeline

.scroll-container {
  scroll-timeline: --scroll-progress block;
}

Define the Keyframes

@keyframes fill-progress {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

Attach the Animation

.scroll-container .progress-bar {
  transform-origin: left;
  animation: fill-progress linear both;
  animation-timeline: --scroll-progress;
}

The progress bar changes as the scroll container moves through its scrollable range.

Declaration Order Matters

.progress-bar {
  animation-timeline: --scroll-progress;
  animation: fill-progress linear both;
}

The animation shorthand resets animation-timeline to auto. Place animation-timeline after the animation shorthand.

Correct Declaration Order

.progress-bar {
  animation: fill-progress linear both;
  animation-timeline: --scroll-progress;
}

Animation Duration

Scroll-driven animations use timeline progress rather than ordinary elapsed time. A duration of auto allows the animation to follow the timeline's progress range.

Multiple Animations

.element {
  animation: fade-in linear both, move-up linear both;
  animation-timeline: --scroll-progress, --scroll-progress;
}

Both animations reference the same scroll progress timeline.

Timeline Scope and Visibility

Named timelines are resolved through CSS timeline lookup rules. A timeline is not automatically available to every element on the page.

Timeline on an Ancestor

.scroll-container {
  overflow-y: auto;
  scroll-timeline: --progress block;
}
.scroll-container .progress-bar {
  animation: fill-progress linear both;
  animation-timeline: --progress;
}

The progress bar is a descendant of the element defining the timeline, so it can reference that timeline.

Timeline on a Sibling

.scroll-container {
  scroll-timeline: --progress block;
}
.progress-bar {
  animation: fill-progress linear both;
  animation-timeline: --progress;
}

If the elements are siblings, the progress bar cannot automatically reference the timeline defined on the scroll container.

Using timeline-scope

.demo-wrapper {
  timeline-scope: --progress;
}
.scroll-container {
  overflow-y: auto;
  scroll-timeline: --progress block;
}
.progress-bar {
  animation: fill-progress linear both;
  animation-timeline: --progress;
}

When the scroll container and progress bar are descendants of .demo-wrapper, timeline-scope can make the named timeline available across that subtree.

Avoid Name Conflicts

Use distinct timeline names when multiple scroll containers define independent timelines. Reusing a name can make timeline lookup difficult to understand.

Important Consideration

When an animation does not respond to scrolling, check whether the animation target can resolve the named timeline before changing its keyframes.

Scroll Timelines vs. View Timelines

Scroll progress timelines and view progress timelines are both used for scroll-driven animations, but they measure different kinds of progress.

Feature Scroll Timeline View Timeline
Property scroll-timeline view-timeline
Progress source Scroll position within a scroll container Visibility of a subject within a scrollport
Typical use Reading progress indicators Reveal effects as elements enter the viewport
Related function scroll() view()

Named Scroll Timeline

.container {
  scroll-timeline: --page-progress block;
}

Named View Timeline

.section {
  view-timeline: --section-visibility block;
}

Anonymous Scroll Timeline

.progress-bar {
  animation: fill-progress linear both;
  animation-timeline: scroll();
}

The scroll() function creates an anonymous scroll progress timeline without requiring a named scroll-timeline declaration.

Anonymous View Timeline

.section {
  animation: reveal linear both;
  animation-timeline: view();
}

The view() function creates an anonymous view progress timeline for the animated element.

Choosing a Timeline

Use a scroll timeline when animation progress should represent the scroll container's overall position. Use a view timeline when progress should depend on an element entering, crossing, or leaving the visible region.

Practical Examples

Article Reading Progress

.article-scroll {
  height: 400px;
  overflow-y: auto;
  scroll-timeline: --article-progress block;
}
.article-scroll .progress {
  transform-origin: left;
  animation: fill-progress linear both;
  animation-timeline: --article-progress;
}
@keyframes fill-progress {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

The progress indicator grows as the article container scrolls.

Horizontal Gallery Progress

.gallery {
  display: flex;
  overflow-x: auto;
  scroll-timeline: --gallery-progress inline;
}
.gallery .indicator {
  animation: fill-progress linear both;
  animation-timeline: --gallery-progress;
}

The timeline follows horizontal scrolling in a horizontal writing mode.

Background Color Transition

.scroll-panel {
  overflow-y: auto;
  scroll-timeline: --color-progress block;
}
.scroll-panel .color-box {
  animation: change-color linear both;
  animation-timeline: --color-progress;
}
@keyframes change-color {
  from {
    background-color: #dbeafe;
  }
  to {
    background-color: #2563eb;
  }
}

The color changes according to the container's scroll progress.

Rotating Graphic

.scroll-panel {
  scroll-timeline: --rotation-progress block;
}
.scroll-panel .graphic {
  animation: rotate-graphic linear both;
  animation-timeline: --rotation-progress;
}
@keyframes rotate-graphic {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

The graphic rotates as the scroll position changes.

Multiple Timelines on One Container

.scroll-area {
  overflow: auto;
  scroll-timeline: --vertical-progress block, --horizontal-progress inline;
}

Different animations can reference the vertical and horizontal progress timelines independently.

scroll-timeline Example

This interactive example creates a named scroll progress timeline on a vertically scrolling container. The progress bar and square respond to the same timeline as you scroll through the content.

HTML Example

<div class="scroll-timeline-demo">
  <div class="scroll-area">
    <div class="progress-track">
      <div class="progress-bar"></div>
    </div>
    <div class="content">
      <h3>Scroll-Driven Animation</h3>
      <p>Scroll down to move the animation forward.</p>
      <div class="animated-square"></div>
      <p>Continue scrolling through this content.</p>
      <p>The animation follows scroll progress.</p>
      <p>Scrolling upward reverses the animation.</p>
      <p>Keep scrolling to reach the end.</p>
      <p>You have reached the final section.</p>
    </div>
  </div>
</div>

CSS Example

.scroll-timeline-demo .scroll-area {
  position: relative;
  height: 220px;
  overflow-y: auto;
  border: 1px solid #cbd5e1;
  scroll-timeline: --demo-progress block;
}
.scroll-timeline-demo .progress-track {
  position: sticky;
  top: 0;
  height: 8px;
  background-color: #e2e8f0;
  z-index: 1;
}
.scroll-timeline-demo .progress-bar {
  width: 100%;
  height: 100%;
  background-color: #2563eb;
  transform-origin: left;
  animation: demo-fill linear both;
  animation-timeline: --demo-progress;
}
.scroll-timeline-demo .content {
  padding: 20px;
}
.scroll-timeline-demo .content p {
  margin-bottom: 35px;
}
.scroll-timeline-demo .animated-square {
  width: 50px;
  height: 50px;
  background-color: #2563eb;
  animation: demo-rotate linear both;
  animation-timeline: --demo-progress;
}
@keyframes demo-fill {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}
@keyframes demo-rotate {
  from {
    transform: rotate(0deg);
    background-color: #2563eb;
  }
  to {
    transform: rotate(360deg);
    background-color: #16a34a;
  }
}
Browser Result

Scroll-Driven Animation

Scroll down to move the animation forward.

Continue scrolling through this content.

The animation follows scroll progress.

Scrolling upward reverses the animation.

Keep scrolling to reach the end.

You have reached the final section.

Scroll down inside the example. In supporting browsers, the progress bar fills and the square rotates and changes color as the scroll position advances. Scrolling upward reverses the effects.

Changing the Timeline Axis

.scroll-timeline-demo .scroll-area {
  scroll-timeline: --demo-progress y;
}

The physical y axis also tracks vertical scrolling, regardless of writing mode.

Removing the Timeline

.scroll-timeline-demo .scroll-area {
  scroll-timeline: none;
}

The named timeline is removed, so animations referencing it no longer receive scroll progress.

Reduced Motion

The live demonstration disables its decorative animations when the user requests reduced motion. The scrollable content remains accessible.

Browser Compatibility Note

Browsers without named scroll-driven animation support may display the content without the animated effects. The demonstration does not require JavaScript.

Accessibility Considerations

Scroll-driven animations should enhance an interface without making its content harder to read or navigate.

Respect Reduced Motion Preferences

@media (prefers-reduced-motion: reduce) {
  .decorative-animation {
    animation: none;
  }
}

Disable or simplify decorative effects for users who prefer reduced motion.

Avoid Excessive Movement

Large rotations, scaling, and repeated movement can be distracting when tied directly to scrolling.

Keep Content Readable

Do not make essential text or controls depend on animation progress to become visible.

Maintain Keyboard Scrolling

Ensure custom scroll containers remain operable with a keyboard and have accessible labels when necessary.

Avoid Scroll-Dependent Navigation

Do not require users to scroll through an animation before they can reach important controls or content.

Provide Fallbacks

Content should remain understandable when scroll-driven animations are unsupported or disabled.

Test Different Input Methods

Verify that mouse wheels, touchscreens, trackpads, and keyboard scrolling do not produce confusing effects.

Common Mistakes

Using a Name Without Two Hyphens

.container {
  scroll-timeline: reading-progress block;
}

Named timelines require dashed identifiers such as --reading-progress.

Using an Unsupported Axis

.container {
  scroll-timeline: --progress both;
}

The both keyword is not supported by scroll-timeline-axis. Define separate timelines for different axes.

Forgetting animation-timeline

Creating a named timeline does not automatically attach it to an animation.

Resetting animation-timeline Accidentally

.element {
  animation-timeline: --progress;
  animation: fill-progress linear both;
}

The later animation shorthand resets the timeline association. Declare animation-timeline afterward.

Using the Wrong Axis

A timeline tracking inline scrolling will not progress as expected when the container only scrolls along its block axis.

Defining a Timeline Without Overflow

If the selected axis has no scrollable range, the timeline is inactive.

Referencing a Timeline Outside Its Scope

A sibling animation target cannot automatically resolve a timeline defined on another sibling. Use an appropriate timeline structure or timeline-scope.

Confusing Scroll and View Timelines

scroll-timeline measures scroll progress. view-timeline measures a subject's visibility progress.

Assuming JavaScript Is Required

Supporting browsers can run scroll-driven animations entirely through CSS.

Ignoring Reduced Motion

Decorative animations should account for users who prefer reduced motion.

Important Considerations

Keep the following points in mind when using scroll-timeline:

  • It is a shorthand for scroll-timeline-name and scroll-timeline-axis.
  • Its initial value is none, and it is not inherited.
  • Timeline names use dashed identifiers beginning with two hyphens.
  • The default scrolling axis is block.
  • Supported axes are block, inline, x, and y.
  • Multiple timelines can be declared using comma-separated definitions.
  • Each named timeline tracks scrolling on its selected axis.
  • A timeline needs an applicable scrollable range to produce progress.
  • Scroll progress normally runs from 0% to 100% across the scrolling range.
  • Scrolling backward decreases timeline progress.
  • The property does not create an animation automatically.
  • Use animation-timeline to associate an animation with a named timeline.
  • Declare animation-timeline after the animation shorthand.
  • Named timelines follow CSS timeline lookup and scoping rules.
  • timeline-scope can make named timelines available across a shared subtree.
  • Scroll timelines differ from view progress timelines.
  • Physical axes remain fixed regardless of writing mode.
  • Logical axes follow the writing mode.
  • Provide accessible fallbacks when scroll-driven animations are unsupported.
  • Respect reduced-motion preferences for decorative effects.

Browser Support

The CSS scroll-timeline property has limited availability across browsers. Support for named scroll-driven animation timelines is not as widespread as support for traditional CSS animations.

Chromium-based browsers support modern scroll-driven animation features, while support in Firefox and Safari may depend on browser version or feature availability.

For current compatibility information, visit Can I Use? and search for scroll-timeline.

Use progressive enhancement so that essential content remains available when the property is unsupported.

Feature Detection

@supports (scroll-timeline: --progress block) and (animation-timeline: --progress) {
  .scroll-container {
    scroll-timeline: --progress block;
  }
  .progress-bar {
    animation: fill-progress linear both;
    animation-timeline: --progress;
  }
}

Feature queries can help apply scroll-driven animation styles only when the required syntax is supported.

Specifications

The scroll-timeline property is defined in the CSS Scroll-Driven Animations specification.

CSS Scroll-Driven Animations Level 1

The specification defines named scroll progress timelines, their axes, and how animations can use scroll progress as a timeline.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: scroll-timeline