GooseUI

Components

Scroll Progress


Scroll progress bar on CSS scroll-driven animations, no JavaScript. It tracks the page or any scrolling container; the browser does the math on the compositor.

Browser Support

Scroll-driven animations

Without animation-timeline support the bar stays empty and hidden: it never shows a wrong value.

Your browser:

Preview

Scroll the text in the window: the bar at the top shows how much has been read.

How a lighthouse keeper reads the weather

Long before forecasts reached the coast, the keeper of the northern lighthouse watched the sky from a gallery no wider than a doorstep. Every evening they wrote a single line in the logbook: the color of the sunset, the direction of the smoke, the height of the swell.

Sea birds were the first signal. When gulls came inland and stayed on the fields, a storm was usually a day away. When cormorants dried their wings on the rocks for longer than usual, the air was heavy with moisture and rain followed by night.

The second signal was sound. On a calm evening the bell of the village church carried across the bay, which meant the air near the water was cold and still. A bell that could not be heard at all promised wind from the open sea.

The keeper never trusted a single sign. A red sky in the morning meant little if the barometer was rising, and a falling barometer meant little if the swell stayed low. Only when two or three signs agreed did the line in the logbook turn into a warning for the fishing boats.

Reading the sea

The sea itself kept the longest memory. A long, slow swell arriving from a calm horizon told of a storm hundreds of miles away, and it came days before the first cloud. The keeper counted the seconds between waves and wrote the number down.

Fog was a different craft. It rose from the warm water on cold mornings and could hide the rocks completely, so the foghorn went on at the first white thread over the bay. The keeper listened for the answering horns of passing ships and counted them too.

In winter the work was mostly waiting. The lamp was trimmed, the lens polished, the logbook filled. Those lines are still kept in the museum, and read together they form an almost unbroken record of the weather of a whole century.

The last entry in the book is short. It says that the new automatic station works well and that the keeper will leave in the spring. Under it, in different ink, someone added the color of that evening's sunset.

Installation

npx shadcn@latest add @gooseui/scroll-progress
pnpm dlx shadcn@latest add @gooseui/scroll-progress
yarn dlx shadcn@latest add @gooseui/scroll-progress
bunx --bun shadcn@latest add @gooseui/scroll-progress

Usage

import { ScrollProgress } from "@/components/ui/scroll-progress"

// Whole page: put it once in the layout
<ScrollProgress />

// Any scrolling container: the bar sticks inside it
<div className="h-80 overflow-y-auto">
  <ScrollProgress target="nearest" className="bg-background px-4 py-2" />
  {/* long content */}
</div>

Examples

Whole page

The default target is the page: the bar is fixed to the viewport edge. A live one is at the top of this page.

<ScrollProgress />

Any scrolling container

With target="nearest" the bar sticks inside the nearest scrollable ancestor and tracks it.

<ScrollProgress target="nearest" />

Looks

Thin line, thicker gradient in the theme color, and a percentage on the right. Scroll each window.

Thin line

How a lighthouse keeper reads the weather

Long before forecasts reached the coast, the keeper of the northern lighthouse watched the sky from a gallery no wider than a doorstep. Every evening they wrote a single line in the logbook: the color of the sunset, the direction of the smoke, the height of the swell.

Sea birds were the first signal. When gulls came inland and stayed on the fields, a storm was usually a day away. When cormorants dried their wings on the rocks for longer than usual, the air was heavy with moisture and rain followed by night.

The second signal was sound. On a calm evening the bell of the village church carried across the bay, which meant the air near the water was cold and still. A bell that could not be heard at all promised wind from the open sea.

The keeper never trusted a single sign. A red sky in the morning meant little if the barometer was rising, and a falling barometer meant little if the swell stayed low. Only when two or three signs agreed did the line in the logbook turn into a warning for the fishing boats.

Reading the sea

The sea itself kept the longest memory. A long, slow swell arriving from a calm horizon told of a storm hundreds of miles away, and it came days before the first cloud. The keeper counted the seconds between waves and wrote the number down.

Fog was a different craft. It rose from the warm water on cold mornings and could hide the rocks completely, so the foghorn went on at the first white thread over the bay. The keeper listened for the answering horns of passing ships and counted them too.

In winter the work was mostly waiting. The lamp was trimmed, the lens polished, the logbook filled. Those lines are still kept in the museum, and read together they form an almost unbroken record of the weather of a whole century.

The last entry in the book is short. It says that the new automatic station works well and that the keeper will leave in the spring. Under it, in different ink, someone added the color of that evening's sunset.

<ScrollProgress target="nearest" height={2} />

Gradient

How a lighthouse keeper reads the weather

Long before forecasts reached the coast, the keeper of the northern lighthouse watched the sky from a gallery no wider than a doorstep. Every evening they wrote a single line in the logbook: the color of the sunset, the direction of the smoke, the height of the swell.

Sea birds were the first signal. When gulls came inland and stayed on the fields, a storm was usually a day away. When cormorants dried their wings on the rocks for longer than usual, the air was heavy with moisture and rain followed by night.

The second signal was sound. On a calm evening the bell of the village church carried across the bay, which meant the air near the water was cold and still. A bell that could not be heard at all promised wind from the open sea.

The keeper never trusted a single sign. A red sky in the morning meant little if the barometer was rising, and a falling barometer meant little if the swell stayed low. Only when two or three signs agreed did the line in the logbook turn into a warning for the fishing boats.

Reading the sea

The sea itself kept the longest memory. A long, slow swell arriving from a calm horizon told of a storm hundreds of miles away, and it came days before the first cloud. The keeper counted the seconds between waves and wrote the number down.

Fog was a different craft. It rose from the warm water on cold mornings and could hide the rocks completely, so the foghorn went on at the first white thread over the bay. The keeper listened for the answering horns of passing ships and counted them too.

In winter the work was mostly waiting. The lamp was trimmed, the lens polished, the logbook filled. Those lines are still kept in the museum, and read together they form an almost unbroken record of the weather of a whole century.

The last entry in the book is short. It says that the new automatic station works well and that the keeper will leave in the spring. Under it, in different ink, someone added the color of that evening's sunset.

<ScrollProgress target="nearest" height={8} gradient />

With percentage

How a lighthouse keeper reads the weather

Long before forecasts reached the coast, the keeper of the northern lighthouse watched the sky from a gallery no wider than a doorstep. Every evening they wrote a single line in the logbook: the color of the sunset, the direction of the smoke, the height of the swell.

Sea birds were the first signal. When gulls came inland and stayed on the fields, a storm was usually a day away. When cormorants dried their wings on the rocks for longer than usual, the air was heavy with moisture and rain followed by night.

The second signal was sound. On a calm evening the bell of the village church carried across the bay, which meant the air near the water was cold and still. A bell that could not be heard at all promised wind from the open sea.

The keeper never trusted a single sign. A red sky in the morning meant little if the barometer was rising, and a falling barometer meant little if the swell stayed low. Only when two or three signs agreed did the line in the logbook turn into a warning for the fishing boats.

Reading the sea

The sea itself kept the longest memory. A long, slow swell arriving from a calm horizon told of a storm hundreds of miles away, and it came days before the first cloud. The keeper counted the seconds between waves and wrote the number down.

Fog was a different craft. It rose from the warm water on cold mornings and could hide the rocks completely, so the foghorn went on at the first white thread over the bay. The keeper listened for the answering horns of passing ships and counted them too.

In winter the work was mostly waiting. The lamp was trimmed, the lens polished, the logbook filled. Those lines are still kept in the museum, and read together they form an almost unbroken record of the weather of a whole century.

The last entry in the book is short. It says that the new automatic station works well and that the keeper will leave in the spring. Under it, in different ink, someone added the color of that evening's sunset.

<ScrollProgress target="nearest" showPercent />

How it works

The bar scales from 0 to 1 on a scroll() timeline; the percentage animates a registered @property integer shown through counter():

@property --gsp { syntax: "<integer>"; inherits: true; initial-value: 0; }

[data-gsp-bar] {
  transform: scaleX(0);
  transform-origin: left;
}

@supports (animation-timeline: scroll()) {
  [data-target="nearest"],
  [data-target="nearest"] [data-gsp-bar] {
    animation-timeline: scroll(nearest); /* or scroll(root) */
  }
  [data-gsp-bar] { animation: gsp-grow linear both; }
  [data-gooseui-scroll-progress] { animation: gsp-count linear both; }
  [data-gsp-label]::after { content: counter(gsp) "%"; }
}

@keyframes gsp-grow { to { transform: scaleX(1); } }
@keyframes gsp-count { to { --gsp: 100; } }

Props

PropTypeDefaultDescription
target"root" | "nearest""root"Tracked scroller: the page, or the nearest scrollable ancestor (the bar becomes sticky)
colorstringprimaryBar color, any CSS color
heightnumber3Bar thickness in pixels
position"top" | "bottom""top"Edge where the bar sticks
gradientbooleanfalseGradient from a faded to the full color
showPercentbooleanfalsePercentage to the right of the bar (CSS counter)
classNamestring-Additional CSS classes for the wrapper