Skip to content
Interaction

Sticky headers without JavaScript using scroll-state queries

How a header notices in CSS that it is stuck, how it disappears when scrolling down and comes back when scrolling up, what snapped and scrollable can do, how to write it in Tailwind and what browsers without support show.

9 min readBy Leonie RoesmannUpdated: 30 November 2026
CSSContainer queriesNavigationScrolling

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 short version
  • 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.
01

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.

  1. stuck Whether the element is stuck to an edge, such as top, or not at all, none.
  2. snapped Whether the element is snapped, on the x, y, inline or block axis.
  3. scrollable Whether the container can scroll further in a direction, such as top or bottom.
  4. scrolled Which direction the last scroll went, such as bottom or top, and none as long as nothing has scrolled yet.
02

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);  }}
The header is the container; the nav inside gets a background and shadow as soon as the header is stuck.
The container never styles itselfAs with any container query, the query only affects descendants. A rule in @container scroll-state(stuck: top) that targets the header itself has no effect. That is why the header needs an inner element to carry background and shadow.
03

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%;    }  }}
Down hides, up shows. With focus inside the bar it stays put.
Do not lock out the keyboardSomeone tabbing through the page often scrolls down and still ends up in the navigation. Without :focus-within, focus would then sit on a link nobody can see. The rule above keeps the bar visible while something inside it has focus.
04

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;  }}
Every card is its own container. Only the snapped one shows in full.

The query always asks the nearest matching container above the element. Mix up card and content, and you are asking into the void.

05

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>  );}
The variant lives once in the CSS; after that stuck: in front of any class is enough.
The same variant for directionA second variant with scroll-state(scrolled: bottom) and [container-type:scroll-state] on html gives you classes such as scrolled-down:-translate-y-full. The header then has to be a descendant of html, which it always is.
06

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;    }  }}
Readable base version; the query only removes the background at the top of the page.
Query as a requirement
  • 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.
Query as an addition
  • 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.
Share
Written by
Leonie RoesmannDesign engineering

We build websites and web apps at Systra Studios in Münster and put the building blocks from that work here. What you read comes from real projects, not from a brochure.

Systra Studios: web design from Münster

A new guide every Monday.

Plus one free section with a preview. One email a week, unsubscribe with one click.

You will get a confirmation email. Unsubscribe with one click. Privacy

What guides you sticks to the top.
The headers for it are ready to take.

Navigation sections for the top edge: a sticky bar with a frosted segment group, a header with search as an island, tabs with a stretching marker. Copy them and use container-type: scroll-state to decide how the bar looks once it is stuck.

  • One file per component, as source code in your own project.
  • Built with React, TypeScript and Tailwind CSS v4.
  • All three respect reduced motion.
Browse navigation sections
FAQ

Frequently asked questions

Didn't find your question? Write to us, we answer ourselves.

Get in touch

With a scroll-state query. The element with position: sticky also gets container-type: scroll-state, and a child inside it gets a rule in @container scroll-state(stuck: top). That rule applies while the element is stuck to the top edge and drops away as soon as it is back in its normal place. It matters that the query can only style the container's descendants, not the container itself. Background, shadow or a reduced height therefore belong on an inner element, for example a nav inside a header. Chrome introduced the query in version 133; according to caniuse, Firefox and Safari did not support it yet as of October 2026. In those browsers the rule has no effect, and the header still sticks, just without the change.

With scroll-state(scrolled: ...). The root element html gets container-type: scroll-state and so becomes the container for the page's scroll state. The header inside it moves up out of view with translate: 0 -100% in @container scroll-state(scrolled: bottom) and comes back as soon as the last scroll went upwards. scrolled describes the direction of the last scroll, not the position, and the value none applies as long as nothing has been scrolled yet. The query arrived in Chrome 144. Because the header simply stays visible without the query, this is purely an addition. A rule with :focus-within should keep it visible while a link inside it has keyboard focus.

So far only Chromium-based browsers. Chrome introduced stuck, snapped and scrollable in version 133, and the Chrome team presented them in January 2025. The scrolled query for scroll direction arrived in Chrome 144. caniuse lists the feature as a whole for Chrome and Edge from version 144, plus Opera and Samsung Internet. Firefox up to version 164 and Safari up to Technology Preview 27.3 do not support it there yet. Using usage data for October 2026, caniuse puts it at around 70 percent of page views worldwide. To check whether a browser knows the queries, write @supports (container-type: scroll-state).

Yes, through a variant of your own. Tailwind 4 has the @custom-variant directive, and its long form may contain at-rules into which the class's content is inserted at @slot. A stuck variant with @container scroll-state(stuck: top) { @slot; } then produces classes such as stuck:bg-white or stuck:shadow-md. You set the container with an arbitrary property in square brackets, [container-type:scroll-state], on the sticky element. As in plain CSS, the classes with the variant belong on a child of the container, not on the container itself.