ScrollPremium

Color Change

A 180 px square pinned inside a 280 px frame: its plain colour slides from indigo to magenta, to cyan and then to green over 520 px of scrolling, and the text of its caption takes the same hue at the same instant. animation-timeline: scroll(), four colours in CSS variables, no JavaScript.

CSSColorScroll

Updated

This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Scroll has 74 effects, including 12 free. Explore the category →

3 usage examples

How you like your rib-eye, blue to well done — online ordering for a grill restaurant — Color Change example 1

① How you like your rib-eye, blue to well done — online ordering for a grill restaurant

WhenA dish page on a grill restaurant's ordering site: four doneness buttons (blue, rare, medium, well done) next to a drawn plate, above the add-to-basket button.
WhyThe slice does not jump from one shade to the next: you watch it go from bright red to brown, as if it stayed on the grill a little longer, and the “Colour at the core” chip follows. Scrolling acts as a hidden slider here: each button calls scrollTo on the area, and the scroll-behavior: smooth of the sold code sets how long the blend lasts.
SettingsFour variables: #a1122b, #c8323f, #b5564d, #8a5a44. A 228 × 288 px area with no visible scrollbar, a 588 px tray (300 px of travel), the square redrawn as an oval 150 × 104 px slice with a brown border, the caption as a white chip. The buttons send the area to 0, 33, 66 and 100% of its travel; in the capture a timer clicks for them every 0.95 s.
Green, blue, red and black courses — mobile guide of a treetop adventure park — Color Change example 2

② Green, blue, red and black courses — mobile guide of a treetop adventure park

WhenThe course guide read on a phone at the foot of the trees: four 200 px cards, one per level, under a header bar that stays stuck to the top of the screen.
WhyThe 14 px dot and the label in the bar take the colour of the course being read: a level marker that stays under the thumb and takes no room. Between two cards the hue goes through a blend (a violet between blue and red); if that bothers you, sharp steps come from doubling the stops, see the FAQ.
SettingsVariables: #15803d, #1d5fd0, #d42a20, #16181c. A 254 × 316 px area, the tray as tall as its content (600 px of travel: one card every 200 px, hence one stop every 33%). The square shrunk to a dot pinned at 15 px, the caption stretched into a 44 px white bar pinned at 0. The area moves on its own at 150 px/s in the capture: a timer in the scene.
Water temperature month by month — front-desk screen of a water sports centre — Color Change example 3

③ Water temperature month by month — front-desk screen of a water sports centre

WhenA wall screen at the front desk of a water sports centre: the months from January to August scroll by on their own, each with the lake temperature and the suggested gear, next to a large disc.
WhyThe disc goes from midnight blue to sea green as the warm months reach the arrow: the season can be read from across the hall, before the figure. The sentence under the disc takes the same hue; the four colours were picked dark so that it stays above 4.5:1 on the light background.
SettingsVariables: #1e3a8a, #1d4ed8, #0e7490, #047857. A 540 × 310 px area, 425 px of travel, a 176 px disc pinned at 44 px, the caption pinned at 240 px, eight 54 px rows. Automatic scrolling at 150 px/s by the scene's timer, cut at the first gesture on the screen.

How it works

Under the .fx-0554-root root, the .sdc-scroll-container area (280 px, overflow-y: auto) holds a .sb-colorchange-content tray 800 px tall: its height sets the travel, 800 − 280 = 520 px. The tray has only two children, both position: sticky: the .sb-colorchange-box square (top: 37px) and the .sb-colorchange-label caption (top: 229px). They therefore sit at the same spot in the frame from the first scrolled pixel to the last — it is the empty tray that passes behind them.

Two keyframes do the work. fx0554Fond animates background-color on the square, fx0554Texte animates color on the caption, with the same four stops (0, 33, 66 and 100%) read from --fx0554-c1 to --fx0554-c4. animation-timeline: scroll() swaps the clock for how far the area has been scrolled. Because a plain colour interpolates, the hue slides without a jolt. Read in Chromium: rgb(99, 102, 241) at the start, rgb(133, 93, 240) at 50 px, rgb(168, 83, 240) at 100 px, exact magenta at 172 px, a lavender blue rgb(108, 128, 225) at 260 px, cyan at 343 px, green at 520 px.

Nothing is remembered: colour is a function of position. Scrolling back up retraces the path, stopping midway leaves the square in its in-between hue. The variables sit on the root, so two copies on a page can carry two palettes; measured with two copies, the second pushed to 520 px (green) while the first stayed at 0 (indigo). Outside @supports (animation-timeline: scroll()), an @supports not rule puts the fourth colour on the square and the caption: the object is coloured, it just no longer changes.

Accessibility

  • Reduced motion: a colour change is not a movement, so the code keeps it as it is under prefers-reduced-motion: reduce (both colour animations still run, checked). Only two details switch off: the pulsing of the “Scroll ↓” hint and the scroll-behavior: smooth of the area.
  • Contrast, worth a close look: the coloured caption sits at 4.4:1 on the #0a0a0f background at the start (indigo), then 5.7:1, 8.1:1 and 7.8:1. The white text inside the square reaches 4.47:1 on indigo, just under the 4.5:1 threshold, and drops to 3.5:1 on magenta, 2.4:1 on cyan and 2.5:1 on green. If that text carries information, write it in #0a0a0f (4.4:1 at worst across the four colours) or darken the palette.
  • Keyboard: the area has tabindex="0", role="region" and an aria-label. Tab lands on it in Chromium, Firefox and WebKit with a 2 px violet outline; four presses of the down arrow move it 160 px in Chromium and 204 px in Firefox. WebKit skipped it before the tabindex was added.
  • What colour does not say: a screen reader announces no hue. The area's aria-label describes the principle and the hint is aria-hidden. If the colour encodes a state (level, step, temperature), back it with visible text or a figure.
  • Touch: a 150 px finger drag moved the area by 147 px in Chromium touch emulation (390 px wide), the colour following the finger. At the end of the travel the gesture goes back to the page.

Browser compatibility

CSS only. animation-timeline: scroll(): Chrome and Edge 115, Safari 26, Firefox 159 according to MDN data. Identical readings in Chromium 149 and WebKit 26.5 (rgb(182, 80, 240) at 120 px in both). Firefox 151 answers no to @supports: the square and the caption are green (#10b981) from the start and stay so, the area scrolls with no visible effect. Variables inside keyframes and position: sticky are no trouble for any of these engines.

Chrome 115+✓ Full (measured in Chromium 149)
Edge 115+✓ Not verified (same engine as Chrome)
Safari 26+✓ Full in the WebKit 26.5 test build; real Safari not verified
Firefox 159+✓ Not verified (support announced by MDN)
Firefox up to 158✓ Static colour, the last of the four (measured in Firefox 151)
iOS 26+ / Android Chrome 115+✓ Not verified on a device (finger drag measured in emulation)

The fallback written in the code is a static colour: without animation-timeline, @supports not applies --fx0554-c4. If the colour has to follow scrolling everywhere, you need a scroll listener that writes a CSS variable — this code does not include one, it is yours to add.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0554-root">
  <div class="sdc-scroll-container" tabindex="0" role="region" aria-label="…">
    <div class="sb-colorchange-content">
      <div class="sb-colorchange-box">…</div>
      <span class="sb-colorchange-label">…</span>
    </div>
  </div>
  <span class="sdc-scroll-hint" aria-hidden="true">…</span>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Colours (CSS — --fx0554-c1 to --fx0554-c4, on the root) #6366f1, #d946ef, #06b6d4, #10b981 Four hues, from the top of the travel to the bottom. Checked with red as c1 and blue as c4: the square starts red and ends blue. Colours of similar lightness keep text laid over them readable.
Stops (CSS — @keyframes fx0554Fond and fx0554Texte) 0%, 33%, 66%, 100% Move a percentage to make a hue arrive sooner; add a line and a fifth variable for one more colour. Edit both keyframes together, otherwise the caption drifts out of tune with the square.
Travel (CSS — .sb-colorchange-content { height: 800px }) 800 px, i.e. 520 px of scrolling 580 px gives 300 px of travel, so the colour changes almost twice as fast under the wheel. With real content in the tray, write height: auto: the travel becomes the length of the text.
Pinned position (CSS — top: 37px on the square, 229px on the caption) square + caption centred in the 280 px 37 px = (280 − 180 − 12 − 14) ÷ 2, and 229 = 37 + 180 + 12. If you resize the square, redo that sum and copy the first value into the tray's padding-top as well.
Shape (CSS — width, height, border-radius of .sb-colorchange-box) 180 × 180 px, 20 px radius border-radius: 50% makes it a disc; 14 px across, a status dot; a border or a clip-path turns it into a pictogram. Only the fill is animated, everything else can be redrawn freely.
Area (CSS — .sdc-scroll-container { height: 280px; overflow-y: auto }) 280 px box Without those two declarations, scroll() reads the scrolling of the whole page. Tried: the colour then runs from first to last over the full height of the document, and the square is only pinned while its tray goes by.
Hint (HTML — span.sdc-scroll-hint) “Scroll ↓” A demo marker placed at the bottom of the root. Delete it once the effect lives in a page where scrolling is obvious.

FAQ

The animated property, and so the look. Color Shift animates background with five gradients on the backdrop of a whole section: a gradient does not interpolate, so the palette flips at once at each stop. Color Change animates background-color, a plain colour, on a pinned object: the hue slides continuously, and the caption text follows it through a second keyframe. Color Shift changes the mood of a section; Color Change tints an object — dot, illustration, gauge — and its label.
Yes, by doubling the stops so that each colour holds for a while. Tried with 0%, 30% for the first, 36%, 63% for the second, 69%, 94% for the third and to for the last: the square stays indigo up to 150 px, turns magenta between 156 and 187 px, holds until 328 px, and so on. The blend then lasts only 6% of the travel, i.e. 31 px.
Three things, all tied to position: sticky. The tray must be taller than the area (800 px against 280 here), otherwise there is nothing to scroll. No element between the square and the area may carry overflow: hidden, auto or scroll: the square would latch onto it. And top must stay below the frame height minus the square's height. In the original version of this effect the square was not pinned at all: centred in the tray, it only showed up after 17 px of scrolling.