Favorites

view() CSS Function

view()
CSS FunctionThis function is supported in some modern browsers, but not all.
Updated 21st November 2026

The view() function creates an anonymous view progress timeline, so an animation follows an element as it scrolls into and out of view.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

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 ↓

Demo Code
HTML Code
<div class="demo-scroller">
	<p>Scroll down &darr;</p>
	<p>Scroll down &darr;</p>
	<p>Scroll down &darr;</p>
	<p>Scroll down &darr;</p>
	<p>Scroll down &darr;</p>
	<p>Scroll down &darr;</p>
	<div class="demo-element"></div>
	<p>Keep scrolling &darr;</p>
	<p>Keep scrolling &darr;</p>
	<p>Keep scrolling &darr;</p>
	<p>Keep scrolling &darr;</p>
	<p>Keep scrolling &darr;</p>
	<p>Keep scrolling &darr;</p>
	</div>
CSS Code
@keyframes demo-reveal {
	from { opacity: 0.15; transform: scale(0.4) rotate(-20deg); background: #4361ee; }
	to { opacity: 1; transform: scale(1) rotate(0); background: #f72585; }
}
.demo-scroller {
	height: 190px;
	width: 270px;
	overflow: auto;
	border: 1px solid #c5c5c5;
	background: #fafafa;
}
.demo-scroller p {
	margin: 0;
	padding: 10px 12px;
	color: #666;
	white-space: nowrap;
}
.demo-element {
	width: 110px;
	height: 110px;
	margin: 10px auto;
	border-radius: 12px;
	animation: demo-reveal linear both;
}
.demo-element {
	animation-timeline: view();
}

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

<div class="wrap">
<h1>CSS view() examples</h1>
<div class="scroller">
<div class="item">Card 1 slides in as it enters the view</div>
<div class="item">Card 2 slides in as it enters the view</div>
<div class="item">Card 3 slides in as it enters the view</div>
<div class="item">Card 4 slides in as it enters the view</div>
<div class="item">Card 5 slides in as it enters the view</div>
<div class="item">Card 6 slides in as it enters the view</div>
<div class="item">Card 7 slides in as it enters the view</div>
<div class="item">Card 8 slides in as it enters the view</div>
</div>
<p class="note">Scroll the gray box. Each card uses animation-timeline: view().</p>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* view() examples */
.scroller {
height: 260px;
overflow-y: auto;
padding: 16px;
border-radius: 12px;
background: #e2e8f0;
}

.item {
margin: 0 0 16px;
padding: 22px;
border-radius: 10px;
background: #fff;
font-weight: 600;
box-shadow: 0 4px 12px rgba(16, 42, 67, 0.08);
animation: reveal linear both;
animation-timeline: view();
animation-range: entry 0% entry 100%;
}

@keyframes reveal {
from { opacity: 0; transform: translateX(-60px) scale(0.9); }
to { opacity: 1; transform: none; }
}
Open in editor

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.

This function is supported in some modern browsers, but not all.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.