Say you have a two-column layout: a main column with content and a sidebar. Say it has a lot of content, with sections that requires scrolling. The sidebar column that is largely empty, such that you can safely put a
position: sticky; table of contents over there for all that content in the main column. A fairly common pattern for documentation.
Bramus Van Damme has a nice tutorial on all this, starting from semantic markup, implementing most of the functionality … Read article “Sticky Table of Contents with Scrolling Active States”