Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

animation-range-start: choose where scroll-driven progress begins

Move the start attachment point without turning a percentage into a time delay.

Version: CSS Modules

Syntax

animation-range-start: normal | <length-percentage> | <timeline-range-name> <length-percentage>?;

animation-range-start defines the beginning of the attachment range. normal selects the start of the associated timeline. A percentage without a named range refers to the complete timeline; a length supplies a distance from its beginning. With a named view range, an offset is measured within that range, and omitting the offset selects its 0% point. This is separate from where the element is positioned and from the keyframe selectors themselves.

With one iteration and duration auto, changing the start while keeping the end fixed changes the distance over which the animation progresses. Before that interval, animation-fill-mode determines whether the starting frame remains visible. Scrolling backward can revisit earlier states: the start is not a one-time event trigger. Use animation-direction for playback direction rather than relying on a reversed attachment interval.

The example uses 800px of scrollable distance, a normal end and linear opacity keyframes. A start of 25% places the beginning at 200px. Offsets 0,200,500,800,500 give opacity 0,0,0.5,1,0.5. Changing the start to 400px gives 0,0.5,1 at offsets 400,600,800. Restoring normal gives 0.5 at 400. Both fill preserves the starting value before the range; these are measured outcomes, not simulated percentages.

Set the range after the animation shorthand, which resets it, and pair the property with an appropriate animation-timeline. A comma-separated list corresponds to animation-name. Support for scroll-driven timelines varies, so provide a useful static fallback. The test rejects a seconds value and does not claim to measure named view-range geometry.

Examples

const style=document.createElement('style');style.textContent='@keyframes fade{from{opacity:0}to{opacity:1}}';document.head.append(style);
const scroller=document.createElement('div');scroller.style.cssText='height:200px;width:200px;overflow:auto;scroll-behavior:auto';
const space=document.createElement('div');space.style.height='1000px';
const box=document.createElement('div');box.style.cssText='height:20px;width:20px;opacity:.2;animation:fade auto linear both;animation-timeline:scroll(nearest block)';
space.append(box);scroller.append(space);document.body.append(scroller);
const frame=()=>new Promise(resolve=>requestAnimationFrame(()=>requestAnimationFrame(resolve)));
const sample=async positions=>{const values=[];for(const y of positions){scroller.scrollTop=y;await frame();values.push(Number(getComputedStyle(box).opacity).toFixed(2));}return values.join(',')};
box.style.animationRangeStart='25%';
const percent=await sample([0,200,500,800,500]);
box.style.animationRangeStart='400px';const length=await sample([400,600,800]);
box.style.animationRangeStart='normal';const normal=await sample([400]);
console.log('end='+getComputedStyle(box).animationRangeEnd+'; start25='+percent+'; start400px='+length+'; normalAt400='+normal+'; seconds='+CSS.supports('animation-range-start','2s'));

Result

end=normal; start25=0.00,0.00,0.50,1.00,0.50; start400px=0.00,0.50,1.00; normalAt400=0.50; seconds=false

Executed in Chromium 157.0.8103.51. The test waits for rendered frames after scrolling; it neither installs a scroll listener nor changes the lesson user’s page.

Sources