What Is scroll‑state() and Why It Matters
CSS scroll‑state() is a media query‑like feature that lets you apply styles based on the current scrolling activity of an element or the viewport. Unlike the traditional :hover or :focus pseudo‑classes, scroll‑state() can detect whether the user is actively scrolling, has stopped, or has scrolled to the top or bottom. This opens up new UI possibilities such as:
Showing a “Back to top” button only after the user has scrolled past a threshold.
Changing a header’s background color when the page is being scrolled.
Triggering lazy‑load animations when the user stops scrolling.
Because the feature is purely CSS, it keeps JavaScript logic minimal and can be leveraged directly in React components.
How to Write a scroll‑state() Query
The syntax follows the same pattern as other media queries:
@media ( scroll-state : scrolling ) { … } @media ( scroll-state : idle ) { … } @media ( scroll-state : top ) { … } @media ( scroll-state : bottom ) { … }
Enter fullscreen…