ReUI
Components

Scrollspy

Dynamically highlights navigation to indicate current visible section in viewport during page scroll

Installation

pnpm dlx shadcn@latest add https://reui.io/r/scrollspy.json

Examples

Default

Loading

Horizontal

Loading

API Reference

This component provides a scrollspy navigation system that highlights the current section in view and keeps the URL hash in sync.

Scrollspy Props

PropTypeDefaultDescription
childrenReactNodeThe navigation structure and anchor elements.
targetRefRefObject<HTMLElement | HTMLDivElement | Document>The scrollable container to observe. Defaults to document.
onUpdate(id: string) => voidCallback fired when the active section changes. Receives the section id.
offsetnumber0Offset in pixels to account for sticky headers or spacing above sections.
smoothbooleantrueIf true, smooth scrolls to the section when a nav item is clicked.
classNamestringAdditional class names for the root div.
dataAttributestring'scrollspy'The data attribute prefix used for anchors and sections.
historybooleantrueIf true, updates the URL hash as the user scrolls or clicks nav items.

Data Attributes

Data AttributeUsageDescription
data-slot="scrollspy"On the root wrapperIdentifies the main Scrollspy container.
data-scrollspy-anchorOn nav anchor elementsThe section id this anchor targets. Example: data-scrollspy-anchor="section-1"
data-scrollspy-offsetOn nav anchor elements (optional)Custom offset for this anchor (overrides global offset prop).
data-scrollspyOn the nav group (optional)Used for grouping anchors, e.g. for styling or nested scrollspy.
data-activeOn anchor elementsApplied to the currently active anchor.