Components

Scrollspy

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

Loading

Installation

pnpm dlx shadcn@latest add @toui/scrollspy

Examples

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

PropTypeDefault
children ReactNode
targetRef RefObject<HTMLElement | HTMLDivElement | Document>
onUpdate (id: string) => void
offset number0
smooth booleantrue
className string
dataAttribute string'scrollspy'
history booleantrue

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.

We use cookies

We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our cookie policy.

By clicking Accept, you agree to our use of cookies.
Learn more.