Why this matters in 2026
Container queries let components adapt to their surroundings, not just the viewport. An icon + text row in a sidebar might need to stack vertically in a narrow rail but flow horizontally in a wide panel. Previously, you'd need media queries tied to the viewport or JavaScript to detect parent size. Now, @container handles it cleanly in CSS.
The logic
container-type: inline-size on the wrapper establishes a containing block for size queries. The @container (min-width: 24rem) rule then checks the wrapper's width, not the viewport. Inside, we flip flex-direction from column to row, and reorganize the content flow accordingly. The icon stays 3rem square; only the layout changes.
Why flexbox? Flex is ideal for one-dimensional reflow. Switching flex-direction is all you need to go from stack to row — no grid rewrite, no position changes.
Accessibility & performance
Icons should be aria-hidden if decorative; otherwise, include descriptive text or aria-label. Focus rings remain intact since we're not removing outline styles. Container queries are performant — browsers recalculate styles only when the container size changes, not on every viewport resize. Avoid nesting too many container queries deep, as that can trigger cascading reflows.
container-type: inline-size on the nearest parent you control, not necessarily the immediate wrapper. This gives you flexibility in where the query boundary sits.