01.26 · Scroll-Based

Scroll-Driven Background Color

The background color changes as you scroll through sections. Best for stories.

Scroll it

Scroll inside the box, or press Play and it scrolls for you.

Try it

Change a setting, then scroll again or press Play.

Colors

On Daylight and Forest the text turns dark on light colors.

Blend

Hard cut shows the change with no blending at all.

Copy the prompt

Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.

Add a scroll-driven background color to [the sections of your page]. Give each section a color, and as the visitor scrolls, change the page background from one section's color to the next in step with their position, blending between them unless the settings ask for a hard cut, so the color follows the scroll both ways. Blend in a perceptual color space so the colors in between stay clean. Check the text against the background at every point, and switch the text to dark when the background turns light. A change of color is not movement, so keep it when the visitor has reduced motion turned on. Match the settings listed below.

Replace the words in brackets with your own element. Your settings are added at the end.

Free and open source. If this helped, a star on GitHub helps other people find it.

Star on GitHub

What it is

The full explanation is in README.md.

Good for

  • Stories
  • Portfolios
  • Case studies

Avoid on

  • Text-heavy pages
  • Forms