CKTIS / CSS
animation-range-end: set the final attachment point
Choose where the selected animation reaches the end of its attached range, while leaving its start independent.
Version: CSS Modules
Syntax
animation-range-end: normal | <length-percentage> | <timeline-range-name> <length-percentage>?;animation-range-end specifies the end of an animation’s attachment range. normal uses the end of the associated timeline. A bare percentage or length measures from the timeline’s start, not backward from its end and not from animation-range-start. With a named view range, such as exit 80%, the offset is relative to that named range; a name alone defaults to its 100% point. A seconds value is not a valid range endpoint.
For a single iteration with duration auto, a fixed earlier endpoint compresses the animation into a shorter portion of the scroll distance. It does not edit the 100% keyframe, stop the page from scrolling or remove the element. What stays visible after the interval depends on animation-fill-mode. Specify an end after the intended start; reversed or coincident attachment points are not a way to request a reverse animation.
The example keeps the start at normal on an 800px scroll distance. With end 50%, opacity at offsets 0,200,400,800 is 0,0.5,1,1. Setting the end to 200px instead gives 0,0.5,1,1 at offsets 0,100,200,400. Restoring normal produces 0.5 at offset 400. These are actual style reads with linear easing and both fill; the same output sequence represents different physical intervals.
The property can contain a comma-separated list matched to animation names. The animation shorthand resets range properties, so put this declaration after it. Keep a static fallback for browsers without scroll-driven animation support. The example covers a scroll progress timeline; named view ranges are explained separately and are not represented as tested geometry here.
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.animationRangeEnd='50%';
const percent=await sample([0,200,400,800]);
box.style.animationRangeEnd='200px';const length=await sample([0,100,200,400]);
box.style.animationRangeEnd='normal';const normal=await sample([400]);
console.log('start='+getComputedStyle(box).animationRangeStart+'; end50='+percent+'; end200px='+length+'; normalAt400='+normal+'; seconds='+CSS.supports('animation-range-end','2s'));Result
start=normal; end50=0.00,0.50,1.00,1.00; end200px=0.00,0.50,1.00,1.00; normalAt400=0.50; seconds=false
Executed in Chromium 157.0.8103.51 after two rendering frames per scroll change. Percentages use the scrollable distance, not the total 1000px content height or the 200px viewport height.