Scroll progress

A reading bar that is attached to the scroll rather than chasing it, and a header that compresses over the first 120 pixels and then stops. Both are CSS animations on a scroll timeline, so the compositor evaluates them with the scroll and neither is ever a frame behind. The bar is information and survives reduced motion; the header’s movement is decoration and does not.

Scroll it

How far is left

this line and the size of the title both settle over the first 120 pixels

What you paste

@keyframes fill{ from{ transform:scaleX(0) } to{ transform:scaleX(1) } }

@supports (animation-timeline: scroll()){
  .bar i{
    animation: fill linear both;
    animation-timeline: scroll(nearest block);   /* duration stays auto */
  }
  .head{                                          /* a settle, not a loop */
    animation: settle linear both;
    animation-timeline: scroll(nearest block);
    animation-range: 0 120px;
  }
}
/* a custom property only animates once it has a type */
@property --hfs{ syntax:"<length>"; inherits:true; initial-value:24px }

When the bar is not inside the scroller — a bar fixed to the window, with the article scrolling the document or a pane — name the timeline instead of asking for the nearest one:

.page{ timeline-scope: --read }        /* a shared ancestor publishes the name */
.article{ scroll-timeline: --read block }
.bar i{ animation: fill linear both; animation-timeline: --read }

Printed, not demonstrated: the sticky form above needs neither timeline-scope nor a name, and showing a thing two ways teaches the wrong one.