Building Type-Safe APIs with Nuxt 3 and Prisma
Learn how to build end-to-end type-safe APIs using Nuxt 3 server routes and Prisma ORM for a seamless developer experience.
Forget media queries for components. Container queries let components respond to their own size, enabling truly reusable layouts.
Mbeah Essilfie
June 27, 2026 at 06:03 AM
Media queries respond to the viewport size. But components don't live in the viewport — they live in containers that can be any size.
A card component in a sidebar needs different styles than the same card in the main content area. Media queries can't solve this.
/* Define a containment context */
.card-container {
container-type: inline-size;
container-name: card;
}
/* Style based on container width */
@container card (min-width: 400px) {
.card {
display: grid;
grid-template-columns: 200px 1fr;
}
}
@container card (max-width: 399px) {
.card {
display: flex;
flex-direction: column;
}
}
Tailwind v3.4+ supports container queries natively:
<div class="@container">
<div class="flex flex-col @md:flex-row @lg:grid @lg:grid-cols-3 gap-4">
<img class="w-full @md:w-48 rounded" src="..." alt="..." />
<div class="@md:flex-1">
<h3 class="text-lg @lg:text-xl font-bold">Card Title</h3>
<p class="text-sm @lg:text-base text-gray-600">Description...</p>
</div>
</div>
</div>
@container class creates a containment context. Then use @sm:, @md:, @lg: prefixes instead of sm:, md:, lg: to query the container instead of the viewport.<template>
<div class="@container">
<article class="
flex flex-col gap-3
@sm:flex-row @sm:gap-4
@md:gap-6
bg-white dark:bg-gray-800 rounded-xl p-4 @md:p-6
">
<img
:src="post.image"
class="rounded-lg w-full @sm:w-32 @md:w-48 aspect-video object-cover"
/>
<div class="flex-1 min-w-0">
<h3 class="font-semibold text-base @md:text-lg truncate">
{{ post.title }}
</h3>
<p class="hidden @sm:block text-sm text-gray-500 line-clamp-2">
{{ post.excerpt }}
</p>
</div>
</article>
</div>
</template>
Container queries are supported in all modern browsers (Chrome 105+, Firefox 110+, Safari 16+). For older browsers, the component falls back to the mobile/default layout — a perfectly graceful degradation.
| Use Case | Container Query | Media Query |
|---|---|---|
| Reusable component layouts | ✅ | ❌ |
| Page-level layout shifts | ❌ | ✅ |
| Sidebar vs main content | ✅ | ❌ |
| Navigation responsive behavior | ❌ | ✅ |
Container queries make components truly portable. Use them everywhere a component might appear in different-sized containers.
Fullstack Software Developer
Learn how to build end-to-end type-safe APIs using Nuxt 3 server routes and Prisma ORM for a seamless developer experience.
Go beyond basic utility classes and learn how to build cohesive, maintainable design systems with Tailwind CSS.
Understand the power of Vue 3's Composition API through practical, real-world composable patterns that you can use today.
