Creating a scroll-spy with 2 lines of CSS
This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).
A new CSS property called scroll-target-group combined with the :target-current pseudo-class enables developers to create scroll-spy table of contents with just two lines of CSS. This feature, landing in Chrome 140, eliminates the need for JavaScript when building navigation that highlights the current section as users scroll.
Table of contents
IntroductionSpec examplescroll-target-groupTLDR; the 2 lines of CSSSmoother navigationProgressive enhancementAccessibility considerationsConclusionSort: