query-feature
Scroll state() — CSS reference
Scroll-state queries inspect a selected scroll-state container, such as a sticky header that becomes stuck at its top inset. The condition applies to descendants, not the header itself. This example is tested before and after scrolling, not on other scroll-state features.
Formal Syntax & Structure
css syntaxcss
@container scroll-state(stuck: top) { ... }Working Example
Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>scroll-state()</title><style>body{margin:0}#a{padding:8px;background:rgb(232,237,241);color:rgb(0,0,0);box-sizing:border-box}#scroll{height:100px;overflow:auto}#box{position:sticky;top:0;container-type:scroll-state;background:white}#a{height:30px}@container scroll-state(stuck: top){#a{color:rgb(0,100,0)}}</style><body><section id="scrollbox" style="height:100px;overflow:auto"><div style="height:60px">Scroll down</div><header id="box"><div id="a">Sticky header</div></header><div style="height:300px">More content</div></section></body></html>