HTML & CSS

One Container Query Beats Five Breakpoints

A breakpoint is a guess about where a layout breaks. A container query is the layout telling you.

3 min readPublished November 14, 2026
Share on X

Most responsive CSS is written against the viewport, which is a proxy for the only thing that actually matters: how much room the component has. A card in a narrow sidebar and a card in a wide article need different layouts at the same screen width, and no media query can tell them apart.

Container queries fix that. One component, one rule, and it responds to its own box.

The pattern

.card {
  container-type: inline-size;
  display: grid;
  gap: 1rem;
  padding: 1.25rem;
}

@container (min-width: 34rem) {
  .card {
    grid-template-columns: 14rem 1fr;
    align-items: start;
  }
}

Two declarations and a rule. No component prop, no `useMediaQuery`, no JavaScript at all. The same card stacks in a 300px rail and goes two-up in a 720px column, and the browser recalculates on resize, on sidebar collapse, and on a font-size change.

Where a media query still wins

  • Page-level chrome — a nav that becomes a drawer is a decision about the page, not about a component's box.
  • Input modality — `hover: hover` and `pointer: coarse` describe the device, and no container knows about your finger.
  • Print — a different medium entirely.
  • User preferences — reduced motion, contrast, colour scheme.

The useful mental model: media queries ask what is the environment, container queries ask how much room do I have. Most component layout is the second question, which is why most component layout is better served by a container query.

Grid already answered half of this

If the thing you are building is a row of equal cards, you do not need a breakpoint at all. `repeat(auto-fit, minmax(18rem, 1fr))` fits as many columns as the width allows and collapses to one on its own. That single line replaces three media queries and never produces the awkward two-and-a-half-column state.

.grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(min(18rem, 100%), 1fr));
}

The `min(18rem, 100%)` is the detail that matters. Without it, a 320px screen gets a 288px minimum inside a 320px container with padding and overflows by a few pixels — the classic mobile horizontal scrollbar that nobody can reproduce on a desktop.

Fluid type without breakpoints

h1 { font-size: clamp(1.75rem, 1.2rem + 2.4vw, 2.875rem); }
p  { font-size: clamp(1rem,   0.96rem + 0.2vw, 1.125rem); }

Two lines replace the small/medium/large triplet, and the type scales continuously instead of jumping at 768px. Keep a hard floor — that first number — so a 280px screen does not get a 14px headline.

A breakpoint is a guess about where a layout breaks. A container query is the layout telling you.

  • CSS
  • Responsive
  • Layout
KI

Kadirul IslamVerified author

Founder, A.K Solution

Follow on X

Founder of A.K Solution. Full-stack engineer building AI agent tools like KiCode, JSON form engines like ki-forms, and high-scale SEO systems. Obsessed with shipping fast, zero-bloat software that lasts.

More from Kadirul Islam

The Platform Replaced Half Your Utility Library

:has(), container queries, popover, light-dark(). The primitives that used to justify a dependency now ship in the browser.

3 min readCSS

The Model You Pick Is a Price Decision

Frontier benchmarks move monthly. Your invoice does not. Choose on cost per successful task, not on the top row of a leaderboard.

3 min readAI Models