# Scroll Progress

> A thin bar that fills as the page or a scroll container is read, smoothed with a spring.

Source: https://www.honestui.com/docs/animated/scroll-progress

```tsx
"use client";

import { useRef } from "react";

import { ScrollProgress } from "@/registry/default/animated/scroll-progress";

const sections = [
  {
    heading: "Start with the question",
    body: "Every interface answers a question for the person using it. Write that question down before choosing a layout, a color, or a component, and check each screen against it.",
  },
  {
    heading: "Show the state, not the system",
    body: "People care about whether their work is saved, sent, or stuck. Describe the state in their words and keep the internal steps out of the way unless something needs their attention.",
  },
  {
    heading: "Make the next step obvious",
    body: "One primary action per view keeps decisions light. Secondary actions can wait in a menu, and destructive ones should ask before they act.",
  },
  {
    heading: "Let motion explain change",
    body: "A short, consistent transition shows where something came from and where it went. Motion that only decorates is the first thing to cut.",
  },
];

export function ScrollProgressDemo() {
  const containerRef = useRef<HTMLDivElement>(null);

  return (
    <div className="w-full max-w-md overflow-hidden rounded-xl border border-border bg-card">
      <div
        ref={containerRef}
        className="relative h-72 overflow-y-auto [scrollbar-width:none]! [&::-webkit-scrollbar]:hidden!"
      >
        <ScrollProgress container={containerRef} />
        <article className="px-5 py-5">
          <p className="text-xs font-medium text-muted-foreground">Field notes · 4 min read</p>
          <h3 className="mt-1 text-base font-semibold tracking-tight text-foreground">Designing calm software</h3>
          {sections.map((section) => (
            <section key={section.heading} className="mt-5">
              <h4 className="text-[13px] font-medium text-foreground">{section.heading}</h4>
              <p className="mt-1.5 text-[13px] leading-6 text-muted-foreground">{section.body}</p>
            </section>
          ))}
        </article>
      </div>
    </div>
  );
}

```

## Overview [#overview]

Scroll Progress shows how far through a long page or panel the reader is. It tracks the page by default and sits fixed at the top of the viewport. Pass a `container` ref to track a scrolling element instead; the bar then sticks to the top or bottom of that element.

The bar scales from the left edge, which animates on the compositor and stays smooth during fast scrolling. A spring adds a little weight to the motion; it is turned off under reduced motion so the bar tracks scrolling exactly.

## Installation [#installation]

<CliBlock commands="[&#x22;scroll-progress&#x22;]" />

## Usage [#usage]

```tsx
import { ScrollProgress } from "@/components/animated/scroll-progress"

// Track the page
<ScrollProgress />

// Track a scroll container: render the bar as its first child
const ref = useRef<HTMLDivElement>(null)

<div ref={ref} className="h-96 overflow-y-auto">
  <ScrollProgress container={ref} />
  {/* content */}
</div>
```

Set the color and thickness with `className`, for example `h-1 bg-primary`. Inside a container, the bar cancels its own default height with a negative margin so content does not shift; if you change the height, adjust the margin to match.

## Accessibility [#accessibility]

The bar is decorative and hidden from assistive technology, because the scroll position is already available to people using a screen reader or keyboard. If reading progress matters to the task, such as a required agreement, state it in text as well.

## API Reference [#api-reference]


  ### `container`



">
    Scroll container to track. Omit to track the page.

  ### `position`

type: `&#x22;top&#x22; | &#x22;bottom&#x22;` · default: `&#x22;top&#x22;`

Edge the bar sits on.

  ### `smooth`

type: `boolean` · default: `true`

Smooth the bar with a spring. Ignored under reduced motion.

  ### `className`

type: `string`

Classes for the bar, such as its height and color.
