← All forms ScrollSpy contents 8 of 8
‹ ›

Introduction

Scroll this panel and watch the rail on the left follow. Detection is driven by an activation line rather than scroll-position polling, so the highlighted item is the one you are actually reading.

Because it uses IntersectionObserver there is no scroll listener at all.

Getting started

Put data-bs-spy="scroll" on the scroll container and point data-bs-target at a nav. Only .nav-link elements are activated — a custom table of contents needs that class or nothing highlights.

Configuration

The deprecated offset and method options were removed. Use top-margin (default 12%) to position the activation line — for example 96px to sit below a sticky header.

Troubleshooting

With smooth-scroll on, clicking a link restores the URL hash and moves focus to the target once the scroll settles, which keyboard and screen-reader users need.

Target ids are resolved with getElementById, so ids containing dots, colons or percent-encoding work without manual escaping.