floating-toc

A floating table of contents

Dock-style navigation with scrollspy and a sliding pill highlight. Vanilla JS + CSS, zero dependencies. Scroll down — the active item in the dock follows the section in the center of the screen.

Features

Scrollspy, a sliding pill that follows hover and rests on the active link, an entrance animation, full keyboard and prefers-reduced-motion support, and CSS-variable theming — all in about 2 KB.

Scrollspy

An IntersectionObserver with a center-band rootMargin highlights the section actually in the middle of the viewport, not the one that merely touched an edge.

Animation

Reload the page to watch the capsule rise from the bottom and expand, with the items staggering in. The pill waits until the layout settles, so it never flashes out of place.

Theming

The package ships with three ready-to-use themes — Petrol Glass, Paper, and Ink — each powered by CSS variables on .ftoc. Switch between them or create your own by tweaking colors, radius, spacing, and animation timing without touching the JS.

Accessibility

The active link carries aria-current, focus moves the pill, and every animation is disabled when the user prefers reduced motion. On mobile the dock becomes a horizontal scroller that auto-centers the active item.