# CSS Scroll State Queries

> Query stuck, snapped, and scrollable states directly from CSS

Published: 2024-11-26  
Tags: css, chrome  
Source: https://www.rege-dev.xyz/writing/scroll-state-queries

CSS Scroll State Container Queries let you style elements based on their scroll-related state—whether they're `stuck`, `snapped`, or `scrollable`—directly from CSS, no JavaScript required.

[Read more on MDN →](https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Conditional_rules/Container_scroll-state_queries)

**Experimental feature**
  CSS Scroll State Queries require Chrome 133+. This demo uses `@supports` for progressive enhancement.

```css
/* Define scroll-state container */
.container {
  container-type: scroll-state;
}

/* Query stuck, snapped, or scrollable states */
@container scroll-state(stuck: top) { /* styles */ }
@container scroll-state(snapped: x) { /* styles */ }
@container scroll-state(scrollable: bottom) { /* styles */ }
```

## Stuck State

Query when a sticky element is stuck to an edge. Perfect for adding shadows or visual feedback to sticky headers.

```css
.sticky-container {
  container-type: scroll-state;
}

.sticky-header {
  position: sticky;
  top: 0;
}

@container scroll-state(stuck: top) {
  .header-content {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background: hsl(var(--card));
  }
}
```

_Interactive demo: https://www.rege-dev.xyz/writing/scroll-state-queries_

## Snapped State

Query when a scroll-snap item is snapped to its alignment point. Great for highlighting the active item in carousels.

```css
.carousel {
  scroll-snap-type: x mandatory;
}

.carousel-item {
  container-type: scroll-state;
  scroll-snap-align: center;
}

@container scroll-state(snapped: x) {
  .card {
    opacity: 1;
    transform: scale(1);
  }
}
```

_Interactive demo: https://www.rege-dev.xyz/writing/scroll-state-queries_

## Scrollable State

Query when a container has scrollable overflow in a direction. Use it to show scroll shadows or hide scroll-to-top buttons when not needed.

```css
.scroll-container {
  container-type: scroll-state;
}

@container scroll-state(scrollable: top) {
  .shadow-top { opacity: 1; }
  .scroll-to-top { opacity: 1; }
}

@container scroll-state(scrollable: bottom) {
  .shadow-bottom { opacity: 1; }
}
```

_Interactive demo: https://www.rege-dev.xyz/writing/scroll-state-queries_
