π What Is view-timeline-name?
The view-timeline-name property defines a view timeline for an element. A view timeline progresses based on how the element enters, moves through, and exits the viewport β enabling scroll-linked reveal animations without JavaScript. πβ¨
Once defined, the timeline can be used with animation-timeline to animate elements based on their visibility.
π§© Basic Syntax
Basic Syntax
view-timeline-name: timelineName;β You give the element a timeline identifier (e.g., fadeTimeline).
β That timeline updates based on the elementβs position in the viewport.
π― What Does a View Timeline Track?
- Entry β when the element enters viewport
- Containment β while the element is inside viewport
- Exit β when the element leaves viewport
π Add Direction with view-timeline-axis
Timeline Axis
view-timeline-axis: block; /* vertical scroll */
view-timeline-axis: inline; /* horizontal scroll */β Use block for vertical scrolling pages (most common).
π§ͺ Example: Fade-In Section on Scroll
1οΈβ£ Define a View Timeline
Assign timeline
.section {
view-timeline-name: reveal;
view-timeline-axis: block;
}2οΈβ£ Define the Animation
@keyframes reveal
@keyframes fadeSlide {
0% { opacity: 0; transform: translateY(40px); }
100% { opacity: 1; transform: translateY(0); }
}3οΈβ£ Attach Timeline to Animation
Use animation-timeline
.section {
animation-name: fadeSlide;
animation-timeline: reveal;
animation-range: entry 0% exit 100%;
animation-fill-mode: both;
}β Section fades and slides in as it enters viewport β Animation finishes as it exits viewport
π¨ Example: Cards that Reveal One by One
Cards reveal
.card {
view-timeline-name: cardTimeline;
animation: reveal 1s ease-out;
animation-timeline: cardTimeline;
animation-range: entry 0% exit 90%;
}
@keyframes reveal {
from { opacity: 0; transform: translateY(50px); }
to { opacity: 1; transform: translateY(0); }
}β Each card reveals based on its own position
β No JS needed for scroll detection
π¬ Example: Animate Only When in View
In-view animation
.highlight {
view-timeline-name: highlightTimeline;
view-timeline-axis: block;
animation: glow 1s linear;
animation-timeline: highlightTimeline;
animation-range: contain 0% contain 100%;
}
@keyframes glow {
from { opacity: 0.4; }
to { opacity: 1; }
}β Animation runs only while the element stays inside the viewport.
π¦ Full Demo Example
Full Example
.section {
view-timeline-name: sectionTimeline;
view-timeline-axis: block;
}
.section {
animation: fadeUp 1s ease;
animation-timeline: sectionTimeline;
animation-range: entry 0% exit 100%;
animation-fill-mode: both;
}
@keyframes fadeUp {
from { opacity: 0; transform: translateY(40px); }
to { opacity: 1; transform: translateY(0); }
}β This creates smooth reveal transitions across your entire page.
π§ animation-range + view-timeline-name
Use animation-range to control when the animation starts/ends:
animation-range
animation-range: entry 20% exit 80%;- entry β when element hits the viewport
- exit β when element is leaving
- Percentages map to animation progress
β οΈ Browser Support
- β Chrome 115+
- β Edge 115+
- β Firefox (not yet supported)
- β Safari (partial implementation behind flags)
Note
π οΈ Best Practices
- Use view timelines for reveal and on-scroll effects
- Avoid animating layout-affecting properties (use transform instead)
- Keep animations subtle and meaningful
- Ensure elements have enough scrollable space to animate
- Use animation-fill-mode: both for better polish