Scrollspy

In a table of contents, the section being read. When scrolling stops, a thin line slides from the previous entry to the new one.

Resources

Guide

Install

One package for your framework, which brings the core along. Nothing else to set up: light turns on with the first effect.

State

The library reads state from the HTML: native validity, aria-invalid, aria-busy. You never describe the animation, only the meaning.

Light

It lives on the edge, never on the content. One effect, one reason: at rest, the interface is still, with no frame drawn.

Accessibility

Light doubles the information, never carries it alone. Reduced motion, high contrast and screen readers are taken into account.

FAQ

Without WebGL2, a CSS fallback keeps the same meaning.

Scroll the guide and stop, or click an entry of the table of contents.

Scroll on click
Elasticity
Frames
0
Active effects
0
Renderer
none

When to use it

  • On the table of contents of a long page: documentation, article, spec, product page in sections.
  • Not on the site's main menu: it tells where you are in the site, not in the page (aria-current="page", set by your router).
  • Not on a short page you can see almost at once: the table of contents teaches nothing there.

Recommendations

  • A fixed header? Set scroll-padding-top on the page: the reference line and the click scroll take it into account.
  • Leave a little room at the start of the entries (padding): the current entry's mark sits on the edge of the list.
  • Sub-entries (a list inside the list) stay clickable, but light stays on their top-level entry: a two-level table of contents stays calm.
  • Already using smooth scrolling (Lenis…)? Pass it through scrollTo and return a promise: light and page land together.

Accessibility

The library

  • The current entry carries aria-current="location", announced by screen readers: light doubles the information.
  • At rest, a CSS mark with 3:1 contrast, no shader and no layout shift.
  • Nothing while scrolling; at most 3 effects per second, beyond that the mark moves without sliding.
  • Reduced motion: instant scroll and a fading mark. High contrast: system colors.
  • After a click, focus moves to the section reached, as with a native anchor. An aria-current set by your site is never touched.

Integration

  • A real <nav> with a name (aria-label or a tied heading), and real links to anchors (href="#section").
  • A visible focus on the entries, without relying on light.

WCAG 2.2 criteria: Non-text Contrast · Three Flashes or Below Threshold · Animation from Interactions · Focus Visible · Location

Props

PropTypePurpose
<Scrollspy>childrenA single element: the table of contents, usually a <nav>.
scroll"none" | "smooth" | "fast"Scroll on click: the native anchor (default), or driven by the library. Always instant with reduced motion.
elasticitynumberFrom 0 (default) to 1: the scroll slightly overshoots the section, then settles back.
scrollTo(target, { behavior }) => unknownYour own scrolling (Lenis…). A returned promise marks the end.
rootElementThe scrolling container, the window by default.
--sui-scrollspy-currentCSSColor of the mark, neutral white by default.

Spec

The normative spec for this component: Scrollspy

Availability and resources

Status
available · open source
Packages
@shader-ui/react (React, Next.js)
@shader-ui/core (TypeScript, plain HTML)
Source code
scrollspy.ts (core) · scroll.ts (core) · Scrollspy.tsx (React)