Back to components
ElementNavigationFree

Scrollspy Anchor Links React component

A sticky horizontal bar of section links (Overview, Features, Specs, Reviews) that follows the section in view with a sliding pill or underline, keeps the current link scrolled into view on phones, and fills a progress line as you read.

About the Scrollspy Anchor Links component

Scrollspy Anchor Links is a horizontal bar of in-page links that sticks to the top of the screen and highlights the section you are reading. Clicking a link scrolls smoothly to that section, a pill or an underline slides to the current link as you scroll, and a thin line along the bottom fills as you move through the sections. The bar has a frosted, blurred background so content stays readable under it.

items takes objects with the id of each section and a label. offset is the distance from the top where a section becomes current, usually your header plus this bar (72px by default). variant picks pills or underline, sticky and stickyTop control where it sticks, showProgress toggles the bottom line and size picks sm, md or lg. scrollRef follows a scrolling panel instead of the page. The links are real anchors, so they still jump to their sections without JavaScript.

When to use it

Use Scrollspy Anchor Links on long single pages split into a few big sections, like a product page (Overview, Features, Specs, Reviews) or a landing page. It sticks under the header so any section is one tap away, and shows which one you're in.

For documentation with nested headings, a vertical Table of Contents in a sidebar reads better.

Installation

Add the Scrollspy Anchor Links component to your project with the shadcn CLI. It lands in components/scrollspy-anchor-links.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add @reactframe/scrollspy-anchor-links

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

More Navigation components

Language Switcher
Free
Table of Contents
Free
Side Tab Menu
Free
Mobile Tab Bar
Free
Dot Pager Indicator
Free
Mega Menu
Free