A header with position: sticky looks different at the top of the page than while reading. At the top it sits on the hero and needs no background; once it is stuck, text slides underneath and it needs a background and an edge. Until now CSS could not ask whether an element is currently stuck. The usual solutions were an invisible element with IntersectionObserver or a scroll listener that sets a class. scroll-state queries turn this into a container query: the sticky element becomes the container, and its children ask with @container scroll-state(stuck: top) whether it is stuck. The same technique reports which way the page last scrolled, which element has snapped in a snap container and whether an area can still be scrolled further. Chrome introduced the first three queries in version 133, and scroll direction followed in version 144. According to caniuse, Firefox and Safari do not support scroll-state queries yet, so everything here belongs on top of a version that works without them.
- The sticky element gets container-type: scroll-state, and its children ask with @container scroll-state(stuck: top). The element itself cannot be styled this way, so background and shadow sit on an inner element.
- scrolled reports the direction of the last scroll. With the root element as container, a header disappears when scrolling down and comes back when scrolling up, with no scroll listener.
- snapped matches the snapped element in a snap container, and scrollable asks whether an area can still be scrolled in a given direction. Both replace small scripts in carousels and lists.
- Chrome and Edge support the queries; according to caniuse, Firefox and Safari did not yet as of October 2026. Without support the header simply stays the way it is styled without the query.
What are scroll-state queries in CSS?
scroll-state queries are container queries that ask about scroll state instead of size. An element becomes a container with container-type: scroll-state, and rules in @container scroll-state(...) apply to its descendants depending on whether the container is stuck, snapped, can scroll further or was last scrolled in a particular direction.
There are four queries. stuck asks whether an element with position: sticky is stuck to an edge. snapped asks whether an element with scroll-snap-align is currently snapped. scrollable asks whether a scroll container can still be scrolled further in a direction. scrolled asks which direction the last scroll went. For stuck and snapped the container is the sticky or snapping element itself; for scrollable and scrolled it is the scroll container.
The queries can be combined like media queries. The Chrome team shows examples with not, and and or, such as @container not scroll-state(snapped: x). And container-type may carry several values: scroll-state size makes an element a container for both size and scroll state.
- stuck Whether the element is stuck to an edge, such as top, or not at all, none.
- snapped Whether the element is snapped, on the x, y, inline or block axis.
- scrollable Whether the container can scroll further in a direction, such as top or bottom.
- scrolled Which direction the last scroll went, such as bottom or top, and none as long as nothing has scrolled yet.
How do you tell that a sticky header is currently stuck?
You make the header the container and ask about scroll-state(stuck: top) in a child. The header gets position: sticky, top: 0 and container-type: scroll-state. The nav inside it gets background, edge and shadow only within the query. At the top of the page the bar sits transparent on the hero; while reading it stands out from the text.
Until now this took a script. The common solution was an empty element directly above the header, watched by an IntersectionObserver: when it leaves the screen, the script sets a class. That works, but it needs an extra element, a script and a state that is not set yet on first paint.
.site-header { position: sticky; top: 0; container-type: scroll-state;} .site-header > nav { background: transparent; transition: background-color 200ms ease-out, box-shadow 200ms ease-out;} @container scroll-state(stuck: top) { .site-header > nav { background: white; box-shadow: 0 1px 0 rgb(0 0 0 / 0.08), 0 8px 24px -12px rgb(0 0 0 / 0.25); }}
How do you hide a header when scrolling down and show it when scrolling up?
With scroll-state(scrolled: bottom) on the root element. html gets container-type: scroll-state, which makes the page's scroll state queryable. Inside the query the header slides up out of view with translate: 0 -100%. When the last scroll goes upwards, the query no longer applies and the header comes back.
scrolled describes the direction of the last scroll, not how far the page has scrolled. Una Kravets described the query in December 2025 for Chrome 144 and lists the values: the four sides top, right, bottom and left, the logical ones such as block-start and block-end, the axes x, y, block and inline, and none for the state in which nothing has scrolled yet.
The hiding belongs in a block with prefers-reduced-motion: no-preference if it slides. People who have set reduced motion then get the header without the slide, or you simply leave it in place for them.
html { container-type: scroll-state;} .site-header { position: fixed; inset: 0 0 auto;} @media (prefers-reduced-motion: no-preference) { .site-header { transition: translate 200ms ease-out; } @container scroll-state(scrolled: bottom) { .site-header:not(:focus-within) { translate: 0 -100%; } }}
What can you do with snapped and scrollable?
snapped highlights the snapped element in a snap container; scrollable shows hints only where there is more to come. For snapped the container is the element with scroll-snap-align, so every single card in a carousel. An inner element of each card asks whether its card is currently snapped and only then becomes fully opaque and sharp.
scrollable asks the scroll container. The Chrome team uses it for a back-to-top button that only appears when the page can be scrolled upwards. The same pattern fits a fade at the edge of a wide table that only shows while more columns follow on the right.
.track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory;} .slide { scroll-snap-align: center; container-type: scroll-state;} @container not scroll-state(snapped: x) { .slide > .card { opacity: 0.4; scale: 0.96; }}
The query always asks the nearest matching container above the element. Mix up card and content, and you are asking into the void.
How do you write scroll-state queries in Tailwind?
With a variant of your own through @custom-variant. In the long form of this directive Tailwind 4 allows at-rules, and @slot marks the place where the class is inserted. A stuck variant with @container scroll-state(stuck: top) then produces classes such as stuck:bg-white and stuck:shadow-md.
You set the container with an arbitrary property in square brackets: [container-type:scroll-state] on the header. As in plain CSS, the stuck: classes belong on a child, not on the header itself.
/* app.css */@custom-variant stuck { @container scroll-state(stuck: top) { @slot; }} // SiteHeader.tsxexport function SiteHeader() { return ( <header className="sticky top-0 z-40 [container-type:scroll-state]"> <nav className="flex h-16 items-center justify-between px-6 transition-shadow stuck:bg-white stuck:shadow-md"> <a href="/">Northfield</a> <a href="/contact">Contact</a> </nav> </header> );}
Which browsers support scroll-state queries, and what happens without them?
Chrome and Edge yes, Firefox and Safari not yet. Chrome introduced stuck, snapped and scrollable in version 133, and the Chrome team presented them on 15 January 2025. scrolled arrived in Chrome 144. caniuse lists the feature as a whole for Chrome and Edge from 144 and, with usage data for October 2026, puts it at around 70 percent of page views worldwide. Firefox up to version 164 and Safari up to Technology Preview 27.3 are listed there as not supported.
For a header that is harmless as long as the version without the query holds up on its own. A browser without scroll-state queries drops container-type: scroll-state and the rules inside the query. The header still sticks; it just does not change its background. So readability belongs in the base version: a light background with a subtle edge from the start, and the switch to transparent on the hero only inside the query.
Where the base version needs something different from the version with the query, @supports (container-type: scroll-state) separates the two. The hiding header, for example, simply stays visible all the time without support, and that is a usable result.
.site-header > nav { background: white; box-shadow: 0 1px 0 rgb(0 0 0 / 0.08);} @supports (container-type: scroll-state) { .site-header { container-type: scroll-state; } @container not scroll-state(stuck: top) { .site-header > nav { background: transparent; box-shadow: none; } }}
- The header is transparent from the start, and only the query gives it a background.
- In Firefox and Safari text runs under a transparent bar while reading.
- The header has a background and edge from the start; the query removes them at the top on the hero.
- Without support you get a readable bar, with support one that adapts.






