CSS Container Query Tester - Online @container Playground
Experiment with CSS container queries. Resize a container and see the styles change according to its size, not the viewport. Learn the new spec.
UD5 Toolkit
Live demo & compatibility test for CSS @container scroll-state() — detect stuck & snapped elements
Scroll down — when a sticky header gets stuck at top, the @container scroll-state(stuck: top) query activates.
This section introduces the concept of scroll-state container queries. The header above uses position: sticky; top: 0;.
When you scroll this container, the header will stick to the top edge. The container has container-type: scroll-state enabled.
The CSS @container scroll-state(stuck: top) rule detects this sticky state and applies highlight styles automatically — no JavaScript required (in supported browsers).
The scroll-state container query observes the scrollport for sticky-positioned descendants. When any position: sticky element becomes physically stuck to the specified edge, the query matches.
This is a boolean state query — it's either true or false. You can combine it with other container queries using and / or logic.
Key insight: the query fires for any sticky child inside the container, not just a specific one.
Imagine a table of contents sidebar: when a sticky header is active, you could dim non-relevant items or highlight the current section.
Another use case: sticky table headers that change appearance when "locked" — adding a shadow, changing background, or revealing action buttons.
Scroll-state queries bring these interactions to CSS, eliminating the need for complex IntersectionObserver setups.
As of late 2024, scroll-state container queries are available in Chrome Canary behind the Experimental Web Platform Features flag.
Safari and Firefox are actively working on implementation. This tool helps you test whether your current browser supports the feature natively.
For production, always provide a JavaScript fallback using IntersectionObserver or scroll event listeners.
Scroll-state container queries unlock new possibilities for state-driven styling without JavaScript. Combined with size container queries, they form a powerful responsive design toolkit.
Try the snap demo in the next column, and check the FAQ below for deeper insights.
Scroll to snap cards into place — @container scroll-state(snapped: block) detects when a child is aligned.
Sticky Detection
Snap Detection
Container Declaration
scroll-state container type. This enables purely CSS-driven reactions to scroll interactions without JavaScript.
chrome://flags/#enable-experimental-web-platform-features flag is enabled. Safari and Firefox have expressed interest and are tracking the specification, but native support is not yet available in stable releases. Use @supports (container-type: scroll-state) for feature detection.
stuck: top refers to the physical top edge regardless of writing mode. stuck: block-start is logical — it refers to the block-start edge, which depends on the writing mode (top in horizontal-tb, right in vertical-rl). For most English-language sites, they behave identically. Using logical properties (block-start, block-end, inline-start, inline-end) makes your styles more portable across different writing modes.
scroll-state(stuck: top) query matches if any sticky-positioned descendant inside the container is currently stuck to the top edge. You don't need to target a specific element — the query acts as a global state flag for the entire scroll container. This makes it perfect for patterns like "is any section header currently pinned?" to adjust a table of contents or toolbar.
scroll-state(snapped: block) detects whether the container's scroll position is currently aligned to a snap point in the block direction. For scroll-snap-type: y mandatory, the scroll position will always snap (so the query may always match once scrolling stops). For proximity snapping, the query only matches when close enough to a snap point. You can query snapped: x, snapped: y, snapped: block, snapped: inline, or snapped: both.
IntersectionObserver with a rootMargin that matches the sticky offset, or compare the sticky element's getBoundingClientRect().top against its container's top. For snap detection, listen to the scrollend event and check if scrollTop aligns with any child's offsetTop. Apply CSS classes (.is-stuck, .is-snapped) to replicate the container query behavior. This demo uses exactly this fallback approach for browsers without native support.
container-type: scroll-state size; (or use separate container names) to query both scroll state and dimensions. However, note that container-type: scroll-state alone does not enable size queries — you need to explicitly include size or inline-size. You can also nest containers: an outer container tracks size, while an inner one tracks scroll-state, giving you fine-grained control.
| Query Type | Syntax | Detects | Requires |
|---|---|---|---|
stuck: top |
@container scroll-state(stuck: top) |
Sticky element pinned to top edge | position: sticky; top: 0; on child |
stuck: bottom |
@container scroll-state(stuck: bottom) |
Sticky element pinned to bottom edge | position: sticky; bottom: 0; on child |
stuck: left / right |
@container scroll-state(stuck: left) |
Sticky element pinned horizontally | position: sticky; left: 0; on child + horizontal scroll |
snapped: block |
@container scroll-state(snapped: block) |
Child aligned to block-axis snap point | scroll-snap-type on container + scroll-snap-align on children |
snapped: inline |
@container scroll-state(snapped: inline) |
Child aligned to inline-axis snap point | Horizontal scroll-snap-type |
snapped: both |
@container scroll-state(snapped: both) |
Child aligned in both axes simultaneously | 2D scroll-snap-type |
Experiment with CSS container queries. Resize a container and see the styles change according to its size, not the viewport. Learn the new spec.
Design a layout where nested grids share track sizes with their parent via subgrid. Copy the complete CSS.
Create a pure CSS scroll progress indicator using animation‑timeline: scroll(). No JavaScript. Copy the complete code.
Paste your CSS and see warnings for properties that have limited browser support. Links to CanIUse. Modernize safely.
Query the permission state of camera, microphone, geolocation, and more. See the response and learn the API.
Limit browser gestures on an element: pan‑x, pinch‑zoom, manipulation. Draw on a canvas to test. Mobile dev helper.
Acquire and release locks across tabs. Prevent race conditions in IndexedDB or localStorage. Visual queue and lock state.
Test the Fullscreen API: request fullscreen on a colored div, detect changes, and copy the JavaScript boilerplate.
Create complex linear gradients with any number of color stops, exact angles, and length units. Live preview and CSS code.
Style underlines, overlines, and strike-throughs with colors, wavy styles, and thickness. Modern CSS text‑decoration.
Design a button or card that glows on hover. Adjust shadow color, spread, and transition. Copy the CSS. Rich UI.
Create a realistic letterpress (debossed) text effect using CSS text‑shadow and background. Adjust depth and light direction. Copy code.
Generate a subtle noise/grain texture as a CSS background pattern. Adjust opacity and size. For that film look.
Create a customizable checkerboard or grid background using pure CSS gradients. Adjust cell size and colors. Copy the code.
Upload two images and apply CSS blend modes (multiply, screen, overlay, etc.). See the result and copy the filter CSS. Pure frontend.
Add print styles like removing backgrounds, adding page breaks, setting margins. See print preview instantly.
Create a pure CSS countdown timer with a flipping number effect. Adjust duration and style. No JavaScript needed for display.
Create a glowing or rotating border animation around an element. Copy the CSS keyframes. Pure CSS magic.
Create a custom HTML/CSS progress bar with percentage, colors, and animation. Copy the code. Modern UI element.
Design a realistic neon sign text with multiple layers of glow. Copy the CSS and HTML. Perfect for headers.
A replica of the famous Flexbox Froggy game: solve alignment puzzles by writing CSS. Progress saved locally. Fun frontend learning.
Fetch a website's CSS and extract :root custom properties (‑‑color) to reveal its design token palette. For learning and inspiration.
Find safe mixing ratios for the classic elephant toothpaste demonstration. Volume adjustments for different container sizes.
Recreate the target CSS linear gradient by adjusting stops and colors. A unique game for front‑end developers to master gradients.
Browse and search all Font Awesome 6 icons with preview, class name, and unicode. Copy the HTML snippet. Perfect for web developers.
Create text with a gradient fill using CSS background-clip. Configure colors and direction. Copy the code. Works in modern browsers.
A complete, searchable list of all 140+ named HTML/CSS colors with their hex codes and color previews. Click to copy code. Essential web reference.
Visually experiment with Flexbox container and item properties. See the layout update in real time and copy the CSS. Learn by doing, fully interactive.
Minify JavaScript and CSS code to reduce file size for production. Remove whitespace and comments instantly. Run locally, your code stays private.
Easily create asymmetric border radius values and preview the result. Copy the generated CSS instantly. All interactively and browser-based.