Sticky table of contents (scrollspy)

A long article with a sticky side menu whose link highlights the section currently on screen. On phones the menu becomes a row of links above the text.

scrollspydata-scrollspytable of contentstocstickyanchorarticlenavigation

About this block

data-scrollspy on a nav sets aria-current="true" on the link whose #target is most visible, and clears it on the others. The highlight is plain CSS on aria-current, so you style it any way you like.

How to customize it

  • Every link must be an in-page anchor (#id) pointing at an element with that id. Add or remove links and sections together.
  • scroll-mt-24 on each section keeps its title clear of a fixed header when a link jumps to it.
  • Change the aria-[current=true]: classes on the links to restyle the active state.

Browse other blocks

Same library cards — preview live and grab the code from any block.

View full library