Why build scroll indicators in CSS instead of scripting them?
Scrolling is so ingrained in how people use the web that it rarely gets designed as a feature in its own right. The familiar "there is no fold" argument rests on the premise that users know how to scroll and won't stop at some arbitrary vertical line. Where scroll behavior does need custom treatment, developers usually reach for a mix of CSS and JavaScript, because native options are limited. This demo shows a CSS-only alternative.
The goal is narrower than a continuous scroll-progress bar of the kind made popular by an existing horizontal scrollbar demo. Instead of stretching an indicator smoothly throughout a scroll, the indicator stays hidden until the reader reaches a given section; once that happens, its length increases. Each section carries an indicator that is invisible until it reaches the top of the screen, at which point it changes color and sticks to the viewport's top edge. Scrolling back up reverses the effect: the indicator travels with the content and blends back into invisibility.
The two mechanics: sticky positioning and blending
Two things have to happen for this to work.
- The indicator must change color as it approaches the top of the screen.
- The indicator must remain fixed at the top of the screen and only descend again when its own section is scrolled down to.
Point two is straightforward: position: sticky; on the elements makes them stick at a given screen position while their parent container remains in view. Point one is handled with blend modes.
Because an HTML document's background is white by default, the demo uses white as the base color. The indicator should look white when it sits over that base, and take another color when it overlaps the indicator bar at the top of the screen.
How the overlay blend resolves
CSS blend modes offer many ways to combine colors, and this demo uses the overlay value, which is fairly dynamic. White background yields a white result for the foreground; other background colors yield darker or lighter results depending on what they're mixed with.

That is why the indicator stops are actually black. Over a white background the blend renders them white. Over the indicator container — violet — the black of each stop mixes with the violet and the stops appear dark violet.
Structure and styling
The markup is simple: a sticky container at the very top of the page that holds the indicators once they reach it, followed by three content sections, each headed by an indicator that sticks to that container and blends with it.
<div id="passageWrapper">
<strong>Sections Scrolled ↴</strong>
<!-- Indicator container -->
<div id="passage"></div>
</div>
<!-- Indicator stop -->
<div class=passageStops></div>
<!-- First Section -->
<div class="sections">
<!-- Content -->
</div>
<!-- Another indicator stop -->
<div class="passageStops"></div>
<!-- Second Section -->
<div class="sections">
<!-- Content -->
</div>
<!-- Another indicator stop -->
<div class="passageStops"></div>
<!-- Third Section -->
<div class="sections">
<!-- Content -->
</div>
The CSS sets the .passageStops indicators to black. The overlay blend then makes them read as white against the page background. Three sections means each indicator is one-third of the full width. Each is given position: sticky; with a top distance, so it sticks once it reaches that offset. The former white-looking black indicator then blends with the violet container and shows as dark violet, marking the reader's new position. When sticky positioning releases an indicator, it leaves the violet bar for the white page and disappears again.
.passageStops {
background-color: black; /* Each indicator stop is black */
mix-blend-mode: overlay; /* This makes it appear white on a white background */
width: 33.3%; /* Three sections total, so each section is one-third */
top: calc(1em + 3px);
}
#passage,
.passageStops{
height: 10px;
}
#passageWrapper,
.passageStops {
position: sticky; /* The container and stops should stick to the top */
z-index: 1; /* Make sure the indicator and stops stay at the forefront */
}
#passage {
background: violet; /* Will blend with black to make a darker violet indicator */
margin: 0 0 20px 0;
}
#passageWrapper{
background-color: white; /* Make sure we're working with white to hide indicator stops */
height: 40px;
top: 0px;
}
/* Each stop will shift one-third the width of the indicator container to cover the whole thing when the last section is reached. */
.passageStops:nth-child(4){ margin-left: 33.3%; }
.passageStops:nth-child(6){ margin-left: 66.6%; }
/* More styling, blah blah. */
Possible variations include a non-white background with a different blend mode, or gradients applied to the indicator bar or the individual stops.



