A view timeline maps the position of a subject inside its nearest ancestor scrollport to animation progress. animation-timeline: view() attaches that progress to the animated element, while animation-range can limit the portion of the view interval used.
CSS view timelines: tie optional motion to visible progress
When to use it
An archive card receives a subtle decorative rule as it enters the reading area. Its ordinary border and text are already complete; the animation only adds a small opacity cue. Put the animation shorthand before animation-timeline, because the shorthand resets the timeline to auto. Guard the enhancement with @supports so unsupported browsers keep a static rule rather than accidentally running a time-based animation. The sample removes the animation under reduced motion. Test a short page with no scrolling, a long page, a nested scroller, keyboard navigation, and a large card that is taller than the viewport. The nearest scroller matters: a card inside an overflow panel does not necessarily follow page scrolling. Never tie the only display of case status or completion to scroll progress; readers can stop scrolling before the timeline reaches its end.
.archive-card__rule { opacity: 1; }
@supports (animation-timeline: view()) { .archive-card__rule { animation: rule-reveal 1ms linear both; animation-timeline: view(); animation-range: entry 0% entry 100%; } @keyframes rule-reveal { from { opacity: .35; } to { opacity: 1; } } }
@media (prefers-reduced-motion: reduce) { .archive-card__rule { animation: none; opacity: 1; } }Cost and verification
Opacity is a modest effect, yet scroll-linked animation still needs a real-device check when many cards participate. Keep the animated surface small and avoid layout-changing properties such as width or block size on each scroll frame. Browser support for scroll timelines is uneven, so the static fallback is the primary design. The 1ms duration is a placeholder for the animation declaration; the view timeline, not elapsed time, controls progress. Do not reverse the order of animation and animation-timeline, because a later shorthand silently restores the ordinary document timeline. Verify the chosen range on both small and tall cards; a mathematically valid range can yield an effect that is barely visible.
Common Mistakes
- Do not place animation-timeline before a later animation shorthand.
- Do not make required content depend on scroll progress.
- Do not omit the static fallback and reduced-motion path.
