CSS Scrollbar With Progress Meter

Scrollbars already function as progress indicators: how far the bar has moved down or across tells you how much of an element (often the whole page) you've scrolled through. Strictly speaking, though, they indicate progress rather than meter it—a meter being something that fills up as you go. Some CSS trickery can make the scrollbar behave more like the latter, filling as you scroll.

The catch is that this relies entirely on -webkit- vendor-prefixed scrollbar-styling properties, which are non-standard. The standardized scrollbar-width and scrollbar-color properties can't achieve this effect, though they are likely the safer long-term choice. The vendor-prefixed versions probably aren't going away, so treating the technique as an unusual form of progressive enhancement is a reasonable stance.

What's the trick?

The core technique is hanging a very large box-shadow off the top of the scrollbar thumb—or off its side, for a horizontally scrolling element.

:root {
  --shadow: #43a047;
  --scrollbarBG: #eee;
  --thumbBG: #66bb6a;
}
::-webkit-scrollbar {
  width: 16px;
}
::-webkit-scrollbar-track {
  background: var(--scrollbarBG);
}
::-webkit-scrollbar-thumb {
  background-color: var(--thumbBG);
  box-shadow: 0 -100vh 0 100vh var(--shadow), 0 0 15px 5px black;
}

Demo

The technique first appeared in a Pen by Myk. That example didn't visually distinguish the thumb from the rest of the scrollbar at all, which makes it more meter-like but also harder to use. My demo uses a slightly different color for the thumb.

Can I really use this?

No. Beyond being very strange and non-standard, Safari "flips its lid" with it, and there's no known fix.

For a highly related alternative, there's a favorite CSS trick.

I want to learn more about styling scrollbars

There's a resource for that.