guide2 min read

Container Queries

Style components based on their container size, not the viewport.

Container queries let components respond to their parent container size instead of the viewport. Define a containment context: .card-container { container-type: inline-size; }. Then query it: @container (min-width: 400px) { .card { flex-direction: row; } }. This makes truly reusable components — a card that stacks vertically in a narrow sidebar but goes horizontal in a wide content area, regardless of screen size. Supported in all modern browsers since 2023.