
CSS-Tricks · 7 min readCSS & layout
scroll-state()
The scroll-state() container query lets CSS react to scrolling direction, scrollability, sticky positioning, and snap status without JavaScript. By defining @container rules with specific scroll-state features, developers can animate elements like back‑to‑top links, scroll indicators, and sticky headers based on user scroll behavior.
- Define @container scroll-state() queries to conditionally apply styles based on scroll direction or state
- Combine scrolled and scrollable features to show or hide UI elements as the user reaches page edges
- Avoid layout loops with sticky elements by fixing container height or using transforms