Transition background colors as users scroll through sections, using CSS scroll-timeline or JavaScript IntersectionObserver. Live demos, configurable, copy the code.
The scrollable container has scroll-timeline-name: --bgc-tl and its background is animated with multi-stop @keyframes linked via animation-timeline, all pure CSS. The background smoothly transitions between colors as you scroll through sections.
The viewport background uses 5 keyframe stops with @keyframes. CSS automatically interpolates between colors as scroll advances.
Each section has a data-bg-color attribute. An IntersectionObserver fires when a section enters the viewport, updating the viewport's background property. A CSS transition smoothly interpolates between colors. Works in all modern browsers (97%+ support), no CSS scroll-timeline needed.
Uses IntersectionObserver at 50% threshold. The CSS transition: background Xs ease on the container handles the smooth interpolation.
Get production-ready background transitions with scroll snapping, touch support, and keyboard navigation out of the box.
The CSS approach uses a named Scroll Progress Timeline on the scroll container. The same container's background is animated with multi-stop @keyframes linked to that timeline via animation-timeline. As scroll progress advances from 0% to 100%, the background shifts through each color.
CSS automatically interpolates between keyframe stops, so if stop 0% is blue and stop 25% is green, the background smoothly transitions through cyan as you scroll between sections. Sections are transparent so the animated background shows through.
/* Scroll container with timeline + animated background */
.page {
overflow-y: scroll;
scroll-timeline-name: --page-scroll;
scroll-timeline-axis: block;
animation: bgCycle linear both;
animation-timeline: --page-scroll;
}
/* Background shifts through colors as you scroll */
@keyframes bgCycle {
0% { background: #0d1b4d; } /* Section 1: blue */
25% { background: #064e3b; } /* Section 2: green */
50% { background: #451a03; } /* Section 3: amber */
75% { background: #3b0764; } /* Section 4: purple */
100% { background: #1e3a5f; } /* Section 5: navy */
}
| CSS scroll-timeline | JavaScript (IntersectionObserver) | |
|---|---|---|
| Browser support | Chrome, Edge, Safari 26+ | All browsers (97%+) |
| Smooth interpolation | Automatic between keyframe stops | CSS transition on container |
| Scrubs backward on scroll-up | Automatic | On re-entry (threshold-based) |
| Section-precise control | Percentage-based stops | Per-section data attributes |
| Performance | Compositor thread | Main thread (lightweight) |
| Code size | CSS only | ~15 lines JS |
scroll-timeline-name on the scroll container and animate a background element with multi-stop @keyframes via animation-timeline. With JavaScript: use IntersectionObserver to detect when sections enter the viewport and update the background with a CSS transition for smooth interpolation.scroll-timeline-name: --tl to the scroll container. On a fixed background element, set animation-timeline: --tl and write @keyframes with color stops at 0%, 25%, 50%, 75%, 100%, matching each section. CSS interpolates between stops automatically as you scroll.background-color, background gradients, and color. Write the color transition in @keyframes and link it to a scroll timeline. Works in Chrome 115+, Edge 115+, and Safari 26+.@keyframes stops is automatic. For JavaScript: add transition: background 0.8s ease to the element you are updating, then change its background when a section enters the viewport via IntersectionObserver. The CSS transition handles smooth interpolation.Add scroll transitions, parallax and animations to your site with fullPage.js. One component, 80+ effects.
Powering fullscreen design for Google, Sony, BBC, eBay & more