Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The ViewTimeline interface of the Web Animations API represents a view progress timeline (see CSS scroll-driven animations for more details).

Pass a ViewTimeline instance to the Animation() constructor or the animate() method to specify it as the timeline that will control the progress of the animation.

AnimationTimeline ScrollTimeline ViewTimeline


ViewTimeline() Experimental

Creates a new ViewTimeline object instance.

Instance properties

This interface also inherits the properties of its parent, ScrollTimeline.

subject Read only Experimental

Returns a reference to the subject element whose visibility within its nearest ancestor scrollable element (scroller) is driving the progress of the timeline and therefore the animation.

startOffset Read only Experimental

Returns a CSSNumericValue representing the starting (0% progress) scroll position of the timeline as an offset from the start of the overflowing section of content in the scroller.

endOffset Read only Experimental

Returns a CSSNumericValue representing the ending (100% progress) scroll position of the timeline as an offset from the start of the overflowing section of content in the scroller.

Instance methods

This interface inherits the methods of its parent, ScrollTimeline.


Displaying the subject and offsets of a view progress timeline

In this example, we animate an element with a class of subject along a view progress timeline — it animates when moved upwards through the document as it scrolls. We also output the subject, startOffset, and endOffset values to an output element in the top-right corner.


The HTML for the example is shown below.

<div class="content">

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Risus quis varius quam
    quisque id. Et ligula ullamcorper malesuada proin libero nunc consequat
    interdum varius. Elit ullamcorper dignissim cras tincidunt lobortis feugiat
    vivamus at augue.

    Dolor sed viverra ipsum nunc aliquet. Sed sed risus pretium quam vulputate
    dignissim. Tortor aliquam nulla facilisi cras. A erat nam at lectus urna
    duis convallis convallis. Nibh ipsum consequat nisl vel pretium lectus.
    Sagittis aliquam malesuada bibendum arcu vitae elementum. Malesuada bibendum
    arcu vitae elementum curabitur vitae nunc sed velit.

  <div class="subject animation"></div>

    Adipiscing enim eu turpis egestas pretium aenean pharetra magna ac. Arcu
    cursus vitae congue mauris rhoncus aenean vel. Sit amet cursus sit amet
    dictum. Augue neque gravida in fermentum et. Gravida rutrum quisque non
    tellus orci ac auctor augue mauris. Risus quis varius quam quisque id diam
    vel quam elementum. Nibh praesent tristique magna sit amet purus gravida
    quis. Duis ultricies lacus sed turpis tincidunt id aliquet. In egestas erat
    imperdiet sed euismod nisi. Eget egestas purus viverra accumsan in nisl nisi
    scelerisque. Netus et malesuada fames ac.

  <div class="output"></div>


The CSS for the example looks like this:

.subject {
  width: 300px;
  height: 200px;
  margin: 0 auto;
  background-color: deeppink;

.content {
  width: 75%;
  max-width: 800px;
  margin: 0 auto;

.output {
  position: fixed;
  top: 5px;
  right: 5px;

div {
  font-family: Arial, Helvetica, sans-serif;

h1 {
  font-size: 3rem;

p {
  font-size: 1.5rem;
  line-height: 1.5;


In the JavaScript, we grab references to the subject and output <div>s, then create a new ViewTimeline, associating it with the subject element to specify that the timeline progress is based on this element's visibility through its scrolling ancestor, setting a block axis, and setting inset values to adjust the position of the box in which the subject is deemed to be visible.

We then animate the subject element with the Web Animations API. Last of all, we display the subject, startOffset, and endOffset values in the output element.

const subject = document.querySelector(".subject");
const output = document.querySelector(".output");

const timeline = new ViewTimeline({
  axis: "block",
  inset: [CSS.px("200"), CSS.px("300")],

    opacity: [0, 1],
    transform: ["scaleX(0)", "scaleX(1)"],
    fill: "both",

output.textContent += `Subject element: ${timeline.subject.nodeName}, `;
output.textContent += `start offset: ${timeline.startOffset}, `;
output.textContent += `end offset: ${timeline.endOffset}.`;


Scroll to see the subject element being animated.


Scroll-driven Animations
# viewtimeline-interface

Browser compatibility

BCD tables only load in the browser

See also