Use container queries for component-first responsiveness
8/25/2025
Responsive design often uses global breakpoints (sm:
, md:
, etc.).
But sometimes a component should adapt to its parent container, not the whole viewport.
That’s where container queries come in, which has become a widely supported a CSS feature. Tailwind makes them easy to use:
<div className="@container">
<div className="@md:text-xl @lg:text-2xl">
I resize based on my parent width, not the window size!
</div>
</div>
How it works:
- Add
@container
to the parent element - Use
@
prefixes (@md:
,@lg:
) for container-based breakpoints
This makes components truly reusable — they respond correctly wherever they’re placed, not just at global screen sizes.
Great for dashboards, cards, or nested layouts where viewport breakpoints aren’t enough.
For a more detailed explanation, you can check out the Tailwind CSS Container Queries documentation.
More Dev Tips
Discover more tips and tricks to level up your development skills
New: Your Idea. Our Experts. We'll Build Your SaaS For You.
Our 'Done For You' service simplifies the process, taking your concept and delivering a production-ready MVP or complete SaaS solution.
Start your scalable and production-ready SaaS today
Save endless hours of development time and focus on what's important for your customers with our SaaS starter kits for Next.js, Nuxt 3 and SvelteKit
Get startedStay up to date
Sign up for our newsletter and we will keep you updated on everything going on with supastarter.