Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

view-timeline — named view progress timeline shorthand

The view-timeline property declares a named progress timeline on an element, driven by its position in a scrolling area. It combines the name, axis, and insets; an animation connects to it separately through animation-timeline.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

view-timeline: [ <'view-timeline-name'> [ <'view-timeline-axis'> || <'view-timeline-inset'> ]? ]#;

view-timeline is shorthand for view-timeline-name, view-timeline-axis, and view-timeline-inset. It declares a timeline on the tracked element but does not start an animation itself. Progress depends on the element passing through its nearest scrolling ancestor’s visibility range, rather than elapsed time.

The name is an identifier beginning with --; none declares no named timeline. The component defaults are none, block, and auto. The shorthand resets omitted components. block and inline select logical axes, while x and y select physical axes. Commas separate multiple timelines; # in the grammar denotes such a list.

Optional insets accept one or two values of auto or lengths/percentages. One value applies to both ends; two specify start and end. Positive values shrink the visibility range, negative values expand it; percentages reference the scrollport dimension, while auto uses scroll-padding.

In the example, animation-timeline: --card connects the animation to the declared timeline. Place this declaration after animation, which resets timeline selection. The default full range covers first entry through complete exit. The example ran in an isolated Chromium 157.0.8103.51 environment, and the console output matched the expected output exactly. A CSS declaration alone does not guarantee browser support, so check the example in your local browser too.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Named view progress timeline</title>
  <style>
    .scroller {
      height: 200px;
      width: min(100%, 24rem);
      overflow-y: auto;
      writing-mode: horizontal-tb;
      border: 1px solid;
    }
    .space { height: 300px; }
    .subject { min-height: 100px; background: royalblue; color: white; }
    @supports (view-timeline: --card block) and (view-timeline-inset: 10% 20%) and (animation-timeline: --card) {
      .subject {
        view-timeline: --card block;
        view-timeline-inset: 10% 20%;
        animation: fade linear both;
        animation-duration: auto;
        animation-timeline: --card;
      }
    }
    @keyframes fade {
      from { opacity: 0.35; }
      to { opacity: 1; }
    }
  </style>
</head>
<body>
  <p>Scroll the panel to bring the card into view.</p>
  <div class="scroller" role="region" aria-label="View timeline demo" tabindex="0">
    <div class="space" aria-hidden="true"></div>
    <div class="subject">Timeline card</div>
    <div class="space" aria-hidden="true"></div>
  </div>
  <script>
    if (CSS.supports('view-timeline', '--card block') &&
        CSS.supports('view-timeline-inset', '10% 20%') &&
        CSS.supports('animation-timeline', '--card')) {
      const style = getComputedStyle(document.querySelector('.subject'));
      console.log('Named view timeline syntax: supported');
      console.log(`Computed name and axis: ${style.getPropertyValue('view-timeline-name')} ${style.getPropertyValue('view-timeline-axis')}`);
      console.log(`Computed inset: ${style.getPropertyValue('view-timeline-inset')}`);
      console.log(`Computed animation timeline: ${style.getPropertyValue('animation-timeline')}`);
    } else {
      console.log('Named view timeline syntax: unsupported');
    }
  </script>
</body>
</html>

Result

Named view timeline syntax: supported
Computed name and axis: --card block
Computed inset: 10% 20%
Computed animation timeline: --card

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources