@container scroll-state() is a type of CSS container query. It lets you change a header’s style after scrolling using only CSS, where JavaScript was previously required.
This article introduces how to use scroll-state() and what it can do through a series of demos.
Container queries are introduced in “コンテナークエリーの使い方”. They are useful not only for controlling layouts based on container width, but also for building interactive UIs. This article should give you a sense of the broader possibilities of container queries.
View the demos in this article in Chrome and Edge 144 or later.
How to use @container scroll-state()
This query can be used on descendant elements of an element with container-type: scroll-state. The following values can be specified inside the parentheses of @container scroll-state().
stuck- The element is stuck with
position: sticky
- The element is stuck with
scrollable- The element can be scrolled in one of the four directions
snapped- The element snaps into place with the
scroll-snap-typeproperty
- The element snaps into place with the
scrolled- The most recent scroll direction can be detected
After the colon (:), specify the edge, direction, or axis to detect.
Example of stuck
<div class="item-container">
<div class="item"></div>
</div>
.item-container {
container-type: scroll-state;
position: sticky;
top: 0;
left: 0;
}
.item {
@container scroll-state(stuck: top) {
/* Write styles for when .item-container is stuck */
}
}
The following sections introduce UIs you can build with each scroll state.
stuck: detect sticky positioning
With @container scroll-state(stuck: top), styles can be applied when an element becomes stuck near the top of the viewport with position: sticky. In the following demo, the header background changes to white when the header becomes stuck 20px from the top of the viewport.
Reveal content when stuck
In the following demo, the button expands to reveal navigation links when it reaches the top of the viewport.
Apply styles when sticking ends
Styles can be applied when position: sticky stops sticking. Use the following scroll state queries to detect that moment.
@container scroll-state(stuck: bottom)- A
notcondition (@container not scroll-state(stuck: bottom))
In the following demo, a button in “Section 01” sticks to the bottom of the viewport. Its style changes after you scroll past it.
scrollable: detect scrollability
With @container scroll-state(scrollable: top), styles can be applied when an element can be scrolled upward. In the following demo, a “Back to top” button slides in from the top edge when you scroll down the list. It disappears when you return to the top.
Show arrows for available scroll directions
scrollable also accepts logical directions such as inline-start and inline-end. In a horizontal layout with text flowing from left to right, inline-start means left and inline-end means right.
The following demo shows arrows only in the directions the row of tabs can scroll. The right arrow disappears at the right edge, and the left arrow disappears when you return to the left edge.
The scrollable .tabs element is a container named tabs. Its scroll state controls the visibility of the arrow images inside it. The following excerpt shows the relevant CSS.
.tabs {
container: tabs / scroll-state;
display: flex;
overflow-x: auto;
.previous,
.next {
display: none;
}
@container tabs scroll-state(scrollable: inline-start) {
.previous {
display: block;
}
}
@container tabs scroll-state(scrollable: inline-end) {
.next {
display: block;
}
}
}
The ::scroll-button() pseudo-element handles scrolling when an arrow is clicked. See “Creating a carousel UI with HTML and CSS without JavaScript” for details.
Show scroll hints in a table
The following demo is a table that scrolls horizontally and vertically. It uses scroll state queries to show arrows in the directions where more content is available. The arrows are hidden when you reach the right or bottom edge.
The table’s header row and columns use position: sticky. See “CSS single-axis scroll containers for horizontal tables with sticky headers” for details.
snapped: detect scroll snapping
With @container scroll-state(snapped: block), styles apply when the target is snapped, or is about to snap, along the block axis. Set scroll-snap-type on the scroll container. In horizontal writing, the block axis is vertical. The following demo slightly enlarges the element with a spring effect to make it stand out.
Apply to a carousel UI
The following demo applies this feature to the carousel UI introduced in “Creating a carousel UI with HTML and CSS without JavaScript”. When the “▶” button is clicked, the photos slide horizontally, and an effect reduces their size only while they are sliding. The value passed to snapped is inline, which refers to the inline direction.
Excerpt from the added CSS
.item {
container-type: scroll-state;
img {
transition: scale 0.3s;
transition-delay: 0.2s;
@container not scroll-state(snapped: inline) {
scale: 0.85;
transition-delay: 0s;
}
}
}
scrolled: detect scroll direction
With @container scroll-state(scrolled: bottom), styles can be applied when the container was most recently scrolled downward. Use top to detect a recent upward scroll.
In the following demo, the header hides when you scroll down and reappears when you scroll up.
The scrolled and scrollable conditions are combined with and. The header hides only after scrolling down, while the page can still scroll back up. It stays visible at the top of the page.
html {
--duration-header: 0.3s;
container-type: scroll-state;
}
.site-header {
position: sticky;
top: 0;
translate: 0 0;
transition: translate var(--duration-header) ease;
/* Keep the header visible at the top and hide it only when scrolling down. */
@container scroll-state((scrolled: bottom) and (scrollable: top)) {
translate: 0 -100%;
}
/* Reveal the header when a hidden link receives keyboard focus. */
&:focus-within {
translate: 0 0;
}
}
When scrolling upward makes the condition false, the header returns to its default translate: 0 0. The :focus-within pseudo-class also reveals the header when a link inside it receives keyboard focus.
Browser support
For scroll-state(), stuck, scrollable, and snapped are available in Chrome and Edge 133 or later (February 2025). scrolled requires Chrome and Edge 144 or later (January 2026).
Reference: Can I use…
Conclusion
Scrolling is one of the most basic ways people interact with websites. Responding to scroll actions can make a site more pleasant to use.
Browser support for scroll state queries is still limited, but they can be useful in many situations. Try them when you want to add CSS effects based on scroll state.

