CSS scroll-timeline-axis Property
The CSS scroll-timeline-axis property specifies the scrolling axis used to calculate the progress of a named scroll-driven animation timeline.
It determines whether timeline progress follows horizontal, vertical, block-axis, or inline-axis scrolling. The property works with scroll-timeline-name to define named scroll progress timelines that can control CSS animations through animation-timeline.
scroll-timeline-axis Syntax
The scroll-timeline-axis property accepts one or more axis keywords. Multiple values are separated by commas.
Basic Syntax
selector {
scroll-timeline-axis: block;
}
Available Values
.container {
scroll-timeline-axis: block;
}
.container {
scroll-timeline-axis: inline;
}
.container {
scroll-timeline-axis: x;
}
.container {
scroll-timeline-axis: y;
}
Multiple Axes
.container {
scroll-timeline-axis: block, inline;
}
Each value corresponds to a timeline name in the matching position of the scroll-timeline-name list.
CSS-Wide Keywords
.container {
scroll-timeline-axis: initial;
}
.container {
scroll-timeline-axis: inherit;
}
.container {
scroll-timeline-axis: unset;
}
.container {
scroll-timeline-axis: revert;
}
.container {
scroll-timeline-axis: revert-layer;
}
The property does not accept lengths, percentages, or the both keyword.
Property Values
| Value | Description |
|---|---|
block |
Tracks scrolling along the logical block axis. This is the initial value. |
inline |
Tracks scrolling along the logical inline axis. |
x |
Tracks scrolling along the physical horizontal axis. |
y |
Tracks scrolling along the physical vertical axis. |
initial |
Resets the property to block. |
inherit |
Uses the computed axis values from the parent element. |
unset |
Resets the property to block because it is not inherited. |
revert |
Reverts the property according to CSS cascade origin rules. |
revert-layer |
Reverts the property according to CSS cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | block |
| Inherited | No |
| Applies to | All elements |
| Computed value | List of specified axis keywords |
| Animation type | Discrete |
| Percentages | Not applicable |
| Shorthand property | scroll-timeline |
| Related longhand | scroll-timeline-name |
Valid Values
.container {
scroll-timeline-axis: block;
}
.container {
scroll-timeline-axis: inline;
}
.container {
scroll-timeline-axis: x;
}
.container {
scroll-timeline-axis: y;
}
.container {
scroll-timeline-axis: block, inline;
}
.container {
scroll-timeline-axis: x, y;
}
Invalid Values
.container {
scroll-timeline-axis: both;
}
.container {
scroll-timeline-axis: horizontal;
}
.container {
scroll-timeline-axis: vertical;
}
.container {
scroll-timeline-axis: mandatory;
}
.container {
scroll-timeline-axis: 50%;
}
.container {
scroll-timeline-axis: x y;
}
Use x or y for physical axes and block or inline for logical axes. Separate multiple axis values with commas.
How It Works
The scroll-timeline-axis property determines which scrolling direction supplies progress to a named scroll timeline.
Step 1: Create a Scroll Container
.scroll-container {
height: 300px;
overflow-y: auto;
}
The container can scroll vertically when its content exceeds the available height.
Step 2: Define a Timeline Name
.scroll-container {
scroll-timeline-name: --reading-progress;
}
The name identifies the timeline for use by animations.
Step 3: Select the Scrolling Axis
.scroll-container {
scroll-timeline-axis: block;
}
In horizontal writing, the block axis corresponds to vertical scrolling.
Step 4: Connect an Animation
.scroll-container .progress-bar {
animation: fill-progress linear both;
animation-timeline: --reading-progress;
}
The animation follows the scroll container's progress along the selected axis.
Scroll Position Determines Progress
For a typical scroll container, the timeline begins at 0% at the start of the scrollable range and reaches 100% at the end.
Scrolling Backward
When the user scrolls toward the beginning of the selected axis, timeline progress decreases and the animation can reverse.
The Axis Must Have a Scrollable Range
If the container cannot scroll along the selected axis, the timeline is inactive and cannot provide normal animation progress.
No Layout Changes
The property does not create overflow, change element dimensions, or move content. It only selects the axis used by a scroll progress timeline.
Logical Scrolling Axes
The block and inline values follow the element's writing mode.
Block Axis
.container {
scroll-timeline-name: --progress;
scroll-timeline-axis: block;
}
In horizontal writing, the block axis runs vertically. In vertical writing, it runs horizontally.
Inline Axis
.container {
scroll-timeline-name: --progress;
scroll-timeline-axis: inline;
}
In horizontal writing, the inline axis runs horizontally. In vertical writing, it runs vertically.
Logical Axis Comparison
| Writing Mode | block | inline |
|---|---|---|
horizontal-tb |
Vertical | Horizontal |
vertical-rl |
Horizontal | Vertical |
vertical-lr |
Horizontal | Vertical |
Responsive Writing Modes
.container {
writing-mode: horizontal-tb;
scroll-timeline-axis: inline;
}
@media (min-width: 992px) {
.container {
writing-mode: vertical-rl;
}
}
The timeline changes from horizontal to vertical tracking when the writing mode changes.
Important Consideration
Logical axes are useful for interfaces that support multiple writing modes. They adapt without requiring separate physical-axis declarations.
Physical Scrolling Axes
The x and y values track fixed physical directions regardless of writing mode.
Horizontal Axis
.gallery {
overflow-x: auto;
scroll-timeline-name: --gallery-progress;
scroll-timeline-axis: x;
}
The timeline follows physical horizontal scrolling.
Vertical Axis
.article {
overflow-y: auto;
scroll-timeline-name: --article-progress;
scroll-timeline-axis: y;
}
The timeline follows physical vertical scrolling.
Physical Axis Comparison
| Value | Physical Direction | Changes With Writing Mode |
|---|---|---|
x |
Horizontal | No |
y |
Vertical | No |
Using x With Vertical Writing
.container {
writing-mode: vertical-rl;
overflow-x: auto;
scroll-timeline-axis: x;
}
The timeline still tracks horizontal scrolling.
Using y With Vertical Writing
.container {
writing-mode: vertical-rl;
overflow-y: auto;
scroll-timeline-axis: y;
}
The timeline still tracks vertical scrolling.
Important Consideration
Physical axes are appropriate when the animation must follow a specific screen direction regardless of text layout.
Writing Modes and Text Direction
Writing mode determines how logical axes map to physical scrolling directions. Text direction determines the start and end orientation of the inline axis.
Horizontal Writing
.container {
writing-mode: horizontal-tb;
direction: ltr;
scroll-timeline-axis: block;
}
The block axis runs vertically from top to bottom.
Vertical Right-to-Left Writing
.container {
writing-mode: vertical-rl;
scroll-timeline-axis: block;
}
The block axis runs horizontally from right to left.
Vertical Left-to-Right Writing
.container {
writing-mode: vertical-lr;
scroll-timeline-axis: block;
}
The block axis runs horizontally from left to right.
Right-to-Left Inline Direction
.container {
writing-mode: horizontal-tb;
direction: rtl;
scroll-timeline-axis: inline;
}
The inline axis remains horizontal, but its start and end directions are reversed.
Logical vs. Physical Axes
| Axis | Writing-Mode Dependent | Physical Orientation |
|---|---|---|
block |
Yes | Vertical or horizontal |
inline |
Yes | Horizontal or vertical |
x |
No | Horizontal |
y |
No | Vertical |
Important Consideration
The timeline's progress follows the selected axis from its logical or physical starting position to its ending position. Test direction-sensitive interfaces with both left-to-right and right-to-left content.
Multiple Scroll Timelines
The property accepts comma-separated axis values, allowing one element to define multiple timelines.
Two Named Timelines
.container {
scroll-timeline-name: --vertical-progress, --horizontal-progress;
scroll-timeline-axis: block, inline;
}
The first timeline tracks the block axis, while the second tracks the inline axis.
Physical Axes
.container {
scroll-timeline-name: --horizontal, --vertical;
scroll-timeline-axis: x, y;
}
Each named timeline follows a different physical scrolling axis.
Referencing Different Timelines
.container .horizontal-indicator {
animation: fill-horizontal linear both;
animation-timeline: --horizontal;
}
.container .vertical-indicator {
animation: fill-vertical linear both;
animation-timeline: --vertical;
}
Matching List Positions
Timeline names and axis values are matched by list position. If the lists have different lengths, the axis list is repeated as needed to match the timeline names.
One Axis for Multiple Timelines
.container {
scroll-timeline-name: --first, --second;
scroll-timeline-axis: block;
}
Both named timelines use the block axis.
Important Consideration
Keep timeline names and axes in the same order so their relationships remain easy to understand.
Using the scroll-timeline Shorthand
The scroll-timeline shorthand combines the timeline name and axis in one declaration.
Longhand Declarations
.container {
scroll-timeline-name: --progress;
scroll-timeline-axis: block;
}
Equivalent Shorthand
.container {
scroll-timeline: --progress block;
}
Omitting the Axis
.container {
scroll-timeline: --progress;
}
The omitted axis defaults to block.
Multiple Timelines
.container {
scroll-timeline: --vertical block, --horizontal inline;
}
Shorthand Reset Behavior
.container {
scroll-timeline-name: --progress;
scroll-timeline-axis: inline;
scroll-timeline: --progress;
}
The final shorthand resets the axis to block.
Overriding the Shorthand Axis
.container {
scroll-timeline: --progress block;
scroll-timeline-axis: inline;
}
The later longhand declaration changes the timeline axis to inline.
Important Consideration
Use the shorthand when the name and axis belong together. Use the longhand when only the axis needs to change.
Connecting an Animation
The animation-timeline property connects a CSS animation to a named scroll progress timeline.
Define the Timeline
.scroll-container {
scroll-timeline-name: --reading-progress;
scroll-timeline-axis: block;
}
Define the Keyframes
@keyframes grow-progress {
from {
transform: scaleX(0);
}
to {
transform: scaleX(1);
}
}
Attach the Animation
.scroll-container .progress-bar {
transform-origin: left;
animation: grow-progress linear both;
animation-timeline: --reading-progress;
}
The progress bar grows as the scroll container moves along its block axis.
Changing the Axis
.scroll-container {
scroll-timeline-axis: inline;
}
The animation now follows inline-axis scrolling, provided the container has a scrollable range along that axis.
Declaration Order Matters
.progress-bar {
animation: grow-progress linear both;
animation-timeline: --reading-progress;
}
Declare animation-timeline after the animation shorthand because the shorthand resets the timeline association.
Timeline Visibility
The animated element must be able to resolve the named timeline. A timeline defined on an ancestor is available to its descendants, while sibling elements may require timeline-scope.
Important Consideration
The axis determines where animation progress comes from. The keyframes determine what changes visually.
Scrollable Range and Timeline Progress
A scroll progress timeline requires a scroll container with a usable scrolling range along the selected axis.
Vertical Scroll Range
.container {
height: 300px;
overflow-y: auto;
scroll-timeline-name: --progress;
scroll-timeline-axis: y;
}
When the content exceeds the container's height, vertical scrolling can drive the timeline.
Horizontal Scroll Range
.container {
width: 400px;
overflow-x: auto;
scroll-timeline-name: --progress;
scroll-timeline-axis: x;
}
When the content exceeds the container's width, horizontal scrolling can drive the timeline.
No Scrollable Overflow
.container {
height: 300px;
overflow-y: auto;
scroll-timeline-name: --progress;
scroll-timeline-axis: x;
}
If the container has no horizontal scrolling range, the timeline cannot produce active progress along the selected axis.
Progress Direction
Timeline progress increases from the start of the scrolling range toward its end and decreases when scrolling returns toward the start.
Dynamic Content
Adding or removing content can change the available scrolling range and therefore the relationship between a scroll position and timeline progress.
Overflow Settings
Use appropriate overflow-x and overflow-y settings to establish the intended scroll container. The timeline property itself does not create scrolling.
Important Consideration
When an animation appears inactive, verify that the selected axis matches an actual scrolling direction and that the content creates a scrollable range.
Practical Examples
Vertical Reading Progress
.article-container {
height: 400px;
overflow-y: auto;
scroll-timeline-name: --article-progress;
scroll-timeline-axis: block;
}
.article-container .progress-bar {
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 bar tracks vertical scrolling in a horizontal writing mode.
Horizontal Gallery Progress
.gallery {
display: flex;
overflow-x: auto;
scroll-timeline-name: --gallery-progress;
scroll-timeline-axis: inline;
}
.gallery .indicator {
animation: fill-progress linear both;
animation-timeline: --gallery-progress;
}
The timeline tracks horizontal gallery scrolling in a horizontal writing mode.
Fixed Horizontal Tracking
.gallery {
scroll-timeline-name: --gallery-progress;
scroll-timeline-axis: x;
}
The timeline tracks physical horizontal scrolling regardless of writing mode.
Fixed Vertical Tracking
.article {
scroll-timeline-name: --article-progress;
scroll-timeline-axis: y;
}
The timeline tracks physical vertical scrolling regardless of writing mode.
Two-Dimensional Scroll Area
.scroll-grid {
width: 400px;
height: 300px;
overflow: auto;
scroll-timeline-name: --horizontal, --vertical;
scroll-timeline-axis: x, y;
}
The container defines separate horizontal and vertical scroll progress timelines.
Responsive Axis Selection
.container {
scroll-timeline-name: --progress;
scroll-timeline-axis: block;
}
@media (min-width: 992px) {
.container {
scroll-timeline-axis: inline;
}
}
The selected axis changes at the breakpoint. The container must provide scrolling along the active axis for the timeline to remain functional.
scroll-timeline-axis Example
This interactive example demonstrates two named scroll timelines. The first follows vertical scrolling with scroll-timeline-axis: y, while the second follows horizontal scrolling with scroll-timeline-axis: x.
HTML Example
<div class="timeline-axis-demo">
<div class="vertical-demo">
<h3>Vertical Timeline (y)</h3>
<div class="scroll-area">
<div class="progress-track">
<div class="progress-bar"></div>
</div>
<div class="content">
<p>Section 1</p>
<p>Section 2</p>
<p>Section 3</p>
<p>Section 4</p>
<p>Section 5</p>
</div>
</div>
</div>
<div class="horizontal-demo">
<h3>Horizontal Timeline (x)</h3>
<div class="scroll-area">
<div class="progress-track">
<div class="progress-bar"></div>
</div>
<div class="items">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
</div>
</div>
</div>
</div>
CSS Example
.timeline-axis-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
gap: 20px;
}
.timeline-axis-demo .scroll-area {
position: relative;
height: 180px;
overflow: auto;
border: 1px solid #cbd5e1;
}
.timeline-axis-demo .progress-track {
position: sticky;
top: 0;
left: 0;
height: 8px;
background-color: #e2e8f0;
z-index: 1;
}
.timeline-axis-demo .progress-bar {
width: 100%;
height: 100%;
background-color: #2563eb;
transform-origin: left;
animation: axis-fill linear both;
}
.timeline-axis-demo .vertical-demo .scroll-area {
scroll-timeline-name: --vertical-progress;
scroll-timeline-axis: y;
}
.timeline-axis-demo .vertical-demo .progress-bar {
animation-timeline: --vertical-progress;
}
.timeline-axis-demo .vertical-demo .content {
padding: 15px;
}
.timeline-axis-demo .vertical-demo .content p {
margin-bottom: 65px;
}
.timeline-axis-demo .horizontal-demo .scroll-area {
scroll-timeline-name: --horizontal-progress;
scroll-timeline-axis: x;
}
.timeline-axis-demo .horizontal-demo .progress-bar {
animation-timeline: --horizontal-progress;
}
.timeline-axis-demo .horizontal-demo .items {
display: flex;
gap: 12px;
width: max-content;
padding: 15px;
}
.timeline-axis-demo .horizontal-demo .item {
flex: 0 0 120px;
padding: 35px 10px;
text-align: center;
background-color: #dbeafe;
}
@keyframes axis-fill {
from {
transform: scaleX(0);
}
to {
transform: scaleX(1);
}
}
Vertical Timeline (y)
Section 1
Section 2
Section 3
Section 4
Section 5
Horizontal Timeline (x)
Scroll vertically in the first panel and horizontally in the second. In supporting browsers, each progress bar responds to its corresponding scrolling axis.
Changing the Vertical Axis
.timeline-axis-demo .vertical-demo .scroll-area {
scroll-timeline-axis: block;
}
In horizontal writing, block tracks the same vertical direction as y.
Changing the Horizontal Axis
.timeline-axis-demo .horizontal-demo .scroll-area {
scroll-timeline-axis: inline;
}
In horizontal writing, inline tracks the same horizontal direction as x.
Using the Wrong Axis
.timeline-axis-demo .horizontal-demo .scroll-area {
scroll-timeline-axis: y;
}
If the horizontal panel has no vertical scrollable range, its timeline becomes inactive.
Reduced Motion
The live example disables its decorative progress animations when reduced motion is requested. The scrollable content remains available.
Browser Compatibility Note
Browsers without named scroll-driven animation support may display the panels without animated progress bars.
Accessibility Considerations
Scroll-driven animations should support navigation and understanding without creating unnecessary movement or barriers.
Respect Reduced Motion Preferences
@media (prefers-reduced-motion: reduce) {
.animated-indicator {
animation: none;
}
}
Disable or simplify decorative animations when reduced motion is preferred.
Keep Scroll Containers Accessible
Ensure custom scroll regions can be reached and operated with a keyboard.
Provide Clear Labels
Use accessible names for independent scrolling regions when their purpose is not otherwise clear.
Avoid Essential Animation-Only Information
Do not rely on a scroll-driven animation as the only way to communicate important information.
Avoid Excessive Movement
Large rotations, rapid transformations, and repeated effects may distract users while scrolling.
Maintain Readable Content
Keep text and controls accessible regardless of timeline progress.
Test Different Input Methods
Verify behavior with touch, mouse, trackpad, and keyboard scrolling.
Common Mistakes
Using both as an Axis
.container {
scroll-timeline-axis: both;
}
The both keyword is not valid. Use separate named timelines for different axes.
Using horizontal or vertical
.container {
scroll-timeline-axis: horizontal;
}
Use x for horizontal tracking or y for vertical tracking.
Using Space-Separated Axis Values
.container {
scroll-timeline-axis: x y;
}
Use commas to separate multiple values.
Forgetting the Timeline Name
Setting an axis alone does not create a named timeline. Define a corresponding scroll-timeline-name.
Using the Wrong Axis
A vertical scroll container will not provide horizontal progress if it has no horizontal scrollable range.
Confusing Logical and Physical Axes
block and inline follow writing mode. x and y remain physical directions.
Assuming the Property Creates Overflow
The property does not make an element scrollable. Appropriate overflow and content dimensions are still required.
Mismatching Timeline Lists
Timeline names and axes are matched by list position. Keep their intended order clear.
Overwriting the Axis With a Shorthand
.container {
scroll-timeline-axis: inline;
scroll-timeline: --progress;
}
The later shorthand resets the axis to block.
Ignoring Timeline Scope
Animations must be able to resolve the named timeline through the applicable timeline lookup rules.
Important Considerations
Keep the following points in mind when using scroll-timeline-axis:
- It specifies the scrolling axis for named scroll progress timelines.
- Its initial value is
block, and it is not inherited. - Supported values are
block,inline,x, andy. - Logical axes follow the element's writing mode.
- Physical axes remain fixed regardless of writing mode.
- The property accepts comma-separated lists of axes.
- Axis values correspond to timeline names by list position.
- It is a longhand property of
scroll-timeline. - The related
scroll-timeline-nameproperty defines named timelines. - The property does not create a timeline name by itself.
- The selected axis must have a usable scrolling range for active progress.
- Timeline progress changes as the scroll position changes.
- Scrolling backward decreases timeline progress.
- The property does not create scrolling or alter layout.
- Animations reference named timelines through
animation-timeline. - Timeline lookup and scope determine which animations can use a named timeline.
- The
scroll-timelineshorthand can reset the axis toblock. - Use separate timelines when tracking different axes.
- Provide fallbacks for browsers without scroll-driven animation support.
- Respect reduced-motion preferences for decorative animations.
Browser Support
The CSS scroll-timeline-axis property has limited availability across browsers. It is part of the newer CSS Scroll-Driven Animations features and is not supported as consistently as traditional CSS animation properties.
Modern Chromium-based browsers support named scroll-driven animation timelines. Support in Firefox and Safari may vary by browser version or feature availability.
For current compatibility information, visit Can I Use? and search for scroll-timeline-axis.
When unsupported, the scrolling content remains available, but animations depending on the named timeline may not run.
Feature Detection
@supports (scroll-timeline-axis: block) and (animation-timeline: --progress) {
.scroll-container {
scroll-timeline-name: --progress;
scroll-timeline-axis: block;
}
.progress-bar {
animation: fill-progress linear both;
animation-timeline: --progress;
}
}
Feature queries allow scroll-driven animation styles to be applied only when the required declarations are recognized.
Specifications
The scroll-timeline-axis property is defined in the CSS Scroll-Driven Animations specification.
CSS Scroll-Driven Animations Level 1
The specification defines how physical and logical axes are selected for named scroll progress timelines.
For additional documentation and examples, consult MDN Web Docs.
