<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/scroll-state--uj07bnvlk" -->

---
title: scroll-state() | daily.dev
description: The CSS scroll-state() container query lets you change styles based on scrolling behavior, which can do some things that used to require JavaScript, like...
canonical: https://daily.dev/posts/scroll-state--uj07bnvlk
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: scroll-state() | daily.dev
og:description: The CSS scroll-state() container query lets you change styles based on scrolling behavior, which can do some things that used to require JavaScript, like...
og:url: https://daily.dev/posts/scroll-state--uj07bnvlk
og:image: https://api.daily.dev/og/posts/uJ07BnVLK.png
og:image:alt: scroll-state()
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# scroll-state()

**[CSS-Tricks](https://daily.dev/sources/css_tricks)** · 9 min read · 0 upvotes · 0 comments

## Summary

The CSS scroll-state() container query lets you change styles based on scrolling behavior, which can do some things that used to require JavaScript, like revealing navigation or animating a back-to-top link. It has four features: scrolled, scrollable, stuck, and snapped, each checking a scroll condition. The stuck and snapped features must be set on the element itself, not the scroll container, so styling has to target child elements instead. A noted gotcha: resizing a stuck header based on its own stuck state can create a resize loop, which the source suggests can be mitigated by setting a height on the wrapper or using transforms instead of size changes.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://css-tricks.com/almanac/functions/s/scroll-state>

## Questions this post answers

### What is the CSS scroll-state() container query used for?

The scroll-state() query lets you apply CSS styles conditionally based on scrolling behavior, replacing JavaScript for effects like revealing navigation on scroll up or animating a back-to-top link on scroll down. It's technically a container query, written as @container with scroll-state(), and supports four features: scrolled, scrollable, stuck, and snapped, each with direction-based values like block-end or top.

_Developers adding scroll effects without JS can track CSS features like this on daily.dev._

### Why does my sticky header get stuck in a resize loop when using scroll-state(stuck: top)?

Changing an element's size when it becomes stuck can pull it away from the stuck point, canceling the size change, which makes it stuck again, repeating in a loop that can even block scrolling. The fix is to set a fixed height on the wrapper element doing the sticking, ideally smaller than the header's final size, or use CSS transforms instead of resizing, since transformed elements keep a placeholder that doesn't change with the animation.

_Anyone debugging sticky-header scroll jank can keep up with CSS fixes like this on daily.dev._

### Can I apply styles directly to the element with the stuck or snapped container query in CSS?

No, styles cannot be applied directly to the element carrying the stuck or snapped container, not even using :has(). The container-type and container-name must be set on the sticky or snapped element itself, but the actual style changes have to target its child elements, such as demoting header styles down to the nested header tag.

_Developers wiring up scroll-state() containers can track these CSS quirks on daily.dev._

## Similar posts on daily.dev

- [Directional CSS with scroll-state\(scrolled\)](https://daily.dev/posts/directional-css-with-scroll-state-scrolled--okqxocp8h) · Una Kravets · 29 upvotes · 2 comments
- [Scroll-Driven, Scroll-Triggered, Scroll States, and View Transitions](https://daily.dev/posts/scroll-driven-scroll-triggered-scroll-states-and-view-transitions-xgdb8eccn) · CSS-Tricks · 142 upvotes · 18 comments
- [Toggle \`position: sticky\` to \`position: fixed\` on Scroll – Frontend Masters Blog](https://daily.dev/posts/toggle-position-sticky-to-position-fixed-on-scroll-frontend-masters-blog-lhdc6i72d) · Frontend Masters · 7 upvotes · 0 comments

---

Tags: [#css](https://daily.dev/tags/css)

[View this post on daily.dev](https://daily.dev/posts/scroll-state--uj07bnvlk)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"scroll-state()","url":"https://daily.dev/posts/scroll-state--uj07bnvlk","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/scroll-state--uj07bnvlk"},"datePublished":"2026-11-19T14:58:25.296Z","dateModified":"2026-11-19T14:58:52.529Z","description":"The CSS scroll-state() container query lets you change styles based on scrolling behavior, which can do some things that used to require JavaScript, like...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/f9001af4577f73cab26d2d26032dd8c8?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/f9001af4577f73cab26d2d26032dd8c8?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"CSS-Tricks","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"CSS-Tricks","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/css_tricks","url":"https://daily.dev/sources/css_tricks"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/scroll-state--uj07bnvlk","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"css","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"CSS-Tricks","item":"https://daily.dev/sources/css_tricks"},{"@type":"ListItem","position":3,"name":"scroll-state()"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/scroll-state--uj07bnvlk#faq","mainEntity":[{"@type":"Question","name":"What is the CSS scroll-state() container query used for?","acceptedAnswer":{"@type":"Answer","text":"The scroll-state() query lets you apply CSS styles conditionally based on scrolling behavior, replacing JavaScript for effects like revealing navigation on scroll up or animating a back-to-top link on scroll down. It's technically a container query, written as @container with scroll-state(), and supports four features: scrolled, scrollable, stuck, and snapped, each with direction-based values like block-end or top. Developers adding scroll effects without JS can track CSS features like this on daily.dev."}},{"@type":"Question","name":"Why does my sticky header get stuck in a resize loop when using scroll-state(stuck: top)?","acceptedAnswer":{"@type":"Answer","text":"Changing an element's size when it becomes stuck can pull it away from the stuck point, canceling the size change, which makes it stuck again, repeating in a loop that can even block scrolling. The fix is to set a fixed height on the wrapper element doing the sticking, ideally smaller than the header's final size, or use CSS transforms instead of resizing, since transformed elements keep a placeholder that doesn't change with the animation. Anyone debugging sticky-header scroll jank can keep up with CSS fixes like this on daily.dev."}},{"@type":"Question","name":"Can I apply styles directly to the element with the stuck or snapped container query in CSS?","acceptedAnswer":{"@type":"Answer","text":"No, styles cannot be applied directly to the element carrying the stuck or snapped container, not even using :has(). The container-type and container-name must be set on the sticky or snapped element itself, but the actual style changes have to target its child elements, such as demoting header styles down to the nested header tag. Developers wiring up scroll-state() containers can track these CSS quirks on daily.dev."}}]}
```

