view() CSS Function
The view() function creates an anonymous view progress timeline, so an animation follows an element as it scrolls into and out of view.
Description
The view() CSS function creates an anonymous view progress timeline for scroll-driven animations. It is used with the animation-timeline property and ties an animation to how far the element itself has travelled through the visible area of its scroll container. The animation starts as the element begins to enter the scrollport and finishes when it has completely left the other side.
The optional axis argument chooses the scroll direction to track: block (the default), inline, x or y. The optional inset argument adjusts the area that counts as "in view", using one or two values like auto or lengths; positive values shrink the area and negative values grow it. Usually you combine view() with animation-range to run the animation during a specific phase, such as entry (while the element enters), exit (while it leaves), contain or cover.
/* Fade and slide cards in as they scroll into view */
.card {
animation: reveal linear both;
animation-timeline: view();
animation-range: entry 0% entry 100%;
}
@keyframes reveal {
from { opacity: 0; transform: translateY(40px); }
to { opacity: 1; transform: translateY(0); }
}
/* Horizontal carousel with a 50px inset */
.slide {
animation-timeline: view(x 50px);
}
For animations that follow the overall scroll position of a container rather than a single element, use scroll().
Interactive Demo
Scroll down ↓
Scroll down ↓
Scroll down ↓
Scroll down ↓
Scroll down ↓
Scroll down ↓
Keep scrolling ↓
Keep scrolling ↓
Keep scrolling ↓
Keep scrolling ↓
Keep scrolling ↓
Keep scrolling ↓
Syntax
view() = view( [ <axis> || <'view-timeline-inset'> ]? )
<axis> = block | inline | x | y
<'view-timeline-inset'> = [ [ auto | <length-percentage> ]{1,2} ]#
Values
- <axis>Optional. The scroll direction to track: block (default), inline, x or y.
- <'view-timeline-inset'>Optional. One or two values (auto or a <length-percentage>) that adjust the start and end edges of the area considered "in view". Positive values move the edges inward.
Example
Browser Support
The following information will show you the current browser support for the CSS view() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





