CSS Constraint Lab

Layouts that respond to the space they're in rather than the size of the screen, plus a few takes on the Flexbox Holy Albatross. Open a demo and drag the dashed box, its corner or the toggle to watch it change. Notes on the two articles behind this are in docs/.

01 Conditional Everything A component changes its padding, radius and gap when its container passes a set width. 02 CSS State Machine A component that goes from compact to comfortable to spacious as its container widens. 03 Responsive Personality Card The same card changes from a tiny alert to a richer information card as its container grows. 04 Conditional Shadow A card floats with a shadow when there's room and sits flat when its container gets narrow. 05 Breakpointless App Shell An app shell that moves between a sidebar and stacked navigation depending on how much room it has. 06 Breakpointless Navigation Extra links fold into a popover menu under a hamburger button as space runs out. 07 No-Orphan Layout Flex items wrap once they reach a minimum width, so you never end up with one tiny column on its own. 08 Conditional Typography A heading scales with its component and switches to a compact style when space gets tight. 09 Conditional UI Density A table drops its less important columns as its container gets smaller. 10 Overflow Pressure Padding and gaps shrink smoothly as the container gets narrower, down to a minimum. 11 Edge-Aware Component When its container gets too narrow, the card drops its radius and shadow and runs edge to edge. 12 Self-Organizing Dashboard Cards have a minimum width and the grid rearranges itself around it, with no breakpoints. 13 Gradual Shrink, Sudden Stack Two rules watch the same box. One shrinks padding, gaps and corners smoothly. The other snaps the grid from three columns to one when space runs out. 14 Zero-Query Radius Snap The card's corners go square the moment it touches the edges of the window. It's done with calc() and clamp(). 15 The Holy Albatross Heydon Pickering's original trick. Three items go straight from a row to a column, and you never get two on top with one left below. 16 Container-Scoped Albatross Both articles combined. One calc() switch changes the layout, radius and gap at once, without any @container rules. 17 Chained Albatross Two calc() switches take the layout from one row to two columns to fully stacked. 18 Container Style Queries A container query that checks a custom property instead of a size. Click the toggle to flip @container style(--variant: accent). 19 Shape-Aware Container The card changes layout based on its shape, using @container (aspect-ratio < 1). 20 Animatable Constraint Switch Demo 16's switch again, registered with @property so it eases between layouts instead of snapping. 21 Integer Grid Steps round() works out how many fixed-width columns fit in the container. 22 Aspect-Ratio Gallery Four containers that each react to their shape in a different way: a compound range, orientation, min-aspect-ratio and a one-sided range. 23 Shape-Morphing Child One element that becomes a circle, a square or a rectangle depending on the shape of its container.