Media queries respond to the viewport. Container queries respond to a parent’s width—ideal for cards reused in sidebars and main columns.
Tailwind v3.2+ support
Mark a container with @container (via plugin in v3, built-in in v4). Child utilities use @md: style variants such as @md:flex-row when the container crosses a threshold—not when the whole page does.
CDN playground note
The CDN build supports container queries in recent versions. Enable the container-queries plugin in config when self-hosting:
plugins: [require('@tailwindcss/container-queries')]
Important interview questions and answers
- Q: md: vs @md:?
A:md:watches viewport width;@md:watches the nearest@containerancestor. - Q: When are container queries worth it?
A: Reusable components whose layout should adapt to available space, not global screen size.
Self-check
- Why might a card stay narrow in a sidebar and wide in main content?
- What class marks an element as a query container?