HomeJournalThis post

Build a card layout with container queries

Container queries let reusable cards respond to the space their parent provides, with named containment, intrinsic fallbacks, and component-level QA.

JP
JP Casabianca
Designer/Engineer · Bogotá

A reusable card does not know whether it lives on a wide screen.

It knows whether its container has enough inline space for media, metadata, actions, and text to coexist. A desktop sidebar can be narrower than a mobile page, while an embedded panel on a tablet can be wider than either.

CSS Containment Level 3 defines the containment and conditional rules behind container size queries.

We will build an intrinsic stacked card, designate the owning wrapper as an inline-size query container, and add only the layout transitions the card can justify from its own content.

The component should respond to available space, not guess the route.

01 · OwnName the layout boundary

The parent that controls available card width establishes container-type and an optional stable container name.

02 · AdaptQuery local inline size

The card changes composition only when its content can support the next layout—not at copied device breakpoints.

03 · VerifyExercise every context

Story fixtures place the same component in narrow rail, fluid grid, modal, and wide panel with real content extremes.

Figure 1: The container contract moves responsiveness closer to the component.

Inventory real card contexts

List every wrapper, width constraint, nesting pattern, content role, and interaction state before extracting a responsive component.

I would pressure-test that decision with four questions:

  • Where does the card render?
  • Who controls its width?
  • Which content varies?
  • Which route currently overrides it?

The failure mode here is building the component from one ideal grid screenshot. In reusable product cards that appear in dashboards, sidebars, grids, modals, recommendation rails, and embedded surfaces where viewport width does not describe the space the component actually receives, that can hide the exact boundary a reviewer or teammate needs to understand. My working artifact would be a card context and pressure inventory. I want it close enough to the implementation that it can change the work, not created afterward to decorate the story.

The result I would look for is requirements grounded in actual placements. That is a narrower claim than saying the whole system improved, but it is also one I can verify and defend.

In practice, I would put a card context and pressure inventory beside the question “Where does the card render?” before the first implementation review. The next pass would use “Who controls its width?” to test the boundary, then “Which content varies?” to expose the state most likely to be missed. I would keep “Which route currently overrides it?” for the release check because it asks whether the decision still holds outside the ideal path. The work is ready to move when the artifact can explain the choice and the observed result supports requirements grounded in actual placements.

Choose the query owner

The element that meaningfully constrains available inline space should establish the container, often a slot or list item rather than the card itself.

The practical review starts here:

  • Which ancestor owns width?
  • Will containers nest?
  • Is a name necessary?
  • Can containment change layout?

Those questions keep adding container-type to every component reflexively from becoming the default. I would capture the decision in a wrapper-to-component container contract, then use it while the work is still cheap to change. For context-responsive component design, the artifact should make ownership, constraint, and next action visible without requiring a private explanation.

Success would look like queries resolved against the intended boundary. If I cannot point to that evidence, I have a direction, not a finished decision.

The implementation move is to make a wrapper-to-component container contract part of the working surface. I would use it to answer “Which ancestor owns width?” while scope is still flexible, and “Will containers nest?” before code or content becomes expensive to unwind. During QA, “Is a name necessary?” and “Can containment change layout?” become concrete checks rather than discussion prompts. That sequence turns context-responsive component design into something the team can operate and gives me a specific outcome to report: queries resolved against the intended boundary.

  1. BaseStack without a query

    Semantic source order, readable media, wrapping text, and full-width actions work in every supported context.

  2. CompactRebalance hierarchy

    At a modest container width, metadata and actions share rows while labels still wrap and focus remains visible.

  3. WideCompose horizontally

    Media and content form columns only when minimum readable measures and action space remain available.

Figure 2: Start intrinsic and enhance in layers.

Build an intrinsic baseline

Before any query, the card should wrap, shrink, stack, and preserve semantic order using grid or flex, min-inline-size, and logical properties.

Before implementation, I would answer:

  • Does text overflow?
  • Can actions wrap?
  • Is source order correct?
  • What happens without query support?

The artifact is a query-free stacked card. Its job is to expose the tradeoff early enough that design, engineering, support, or product can disagree with something concrete. The common trap is using the first container query to make the component usable; it moves uncertainty downstream and makes the final interface carry a problem the system never resolved.

For me, the useful receipt is a resilient default in every environment. That connects a container-owned layout contract using inline-size queries, intrinsic defaults, logical properties, content fixtures, and progressive enhancement to an observable result instead of a process claim.

I would test this with one typical case and one boundary case. The typical case should make “Does text overflow?” easy to answer. The boundary should force a decision about “Can actions wrap?” and “Is source order correct?.” I would record both in a query-free stacked card, including the part that stayed unresolved after the first pass. The final check, “What happens without query support?,” is where the artifact earns its place: it either supports a resilient default in every environment, or it shows exactly why another iteration is needed.

Derive thresholds from content

Resize the container with the longest plausible title, translated labels, dense metadata, and full action copy to find genuine pressure points.

I would use these prompts during the working review:

  • When does text become unreadable?
  • When do controls collide?
  • Which badge wraps badly?
  • What minimum media size still communicates?

If the team slips into copying 768px and 1024px viewport breakpoints, the product can still look complete while its operating rule stays ambiguous. I would make a content-driven threshold note the shared reference and keep it small enough to update as evidence changes.

The standard is layout changes justified by component material. That tells me whether the decision helped the product, not merely whether the document was completed.

The working sequence is small: draft a content-driven threshold note, review it against “When does text become unreadable?,” implement the narrowest useful path, and then return with evidence for “When do controls collide?.” I would use “Which badge wraps badly?” to inspect product consequence and “What minimum media size still communicates?” to decide whether the result is stable enough to ship. This keeps copying 768px and 1024px viewport breakpoints visible as a known risk and makes layout changes justified by component material the release receipt rather than a hopeful conclusion.

SignalDecisionWorking note
TextReadable measureTitles, localization, badges, and values determine when columns become cramped before the wrapper does.
ActionsControl integrityButtons need target size, complete labels, focus rings, and predictable wrapping or relocation.
MediaMeaningful cropAspect ratio and object position must preserve the information the image contributes at every card shape.
Figure 3: Query thresholds should follow content pressure.

Use named containers sparingly

Container names help nested components query the right ancestor but create coupling when used as global route vocabulary.

I would pressure-test that decision with four questions:

  • Can the nearest container work?
  • Which nested boundary interferes?
  • Is the name component-owned?
  • What happens if the wrapper changes?

The failure mode here is querying a page-specific container from a generic card. In reusable product cards that appear in dashboards, sidebars, grids, modals, recommendation rails, and embedded surfaces where viewport width does not describe the space the component actually receives, that can hide the exact boundary a reviewer or teammate needs to understand. My working artifact would be a documented named-container exception. I want it close enough to the implementation that it can change the work, not created afterward to decorate the story.

The result I would look for is portable nesting with visible dependencies. That is a narrower claim than saying the whole system improved, but it is also one I can verify and defend.

In practice, I would put a documented named-container exception beside the question “Can the nearest container work?” before the first implementation review. The next pass would use “Which nested boundary interferes?” to test the boundary, then “Is the name component-owned?” to expose the state most likely to be missed. I would keep “What happens if the wrapper changes?” for the release check because it asks whether the decision still holds outside the ideal path. The work is ready to move when the artifact can explain the choice and the observed result supports portable nesting with visible dependencies.

Treat container units as a material

Units such as cqi can scale type or spacing with local width, but need clamps so hierarchy and touch targets do not drift continuously.

The practical review starts here:

  • Which value should scale?
  • What are safe minimum and maximum?
  • Does zoom remain usable?
  • Is discrete change clearer?

Those questions keep making every dimension fluid from becoming the default. I would capture the decision in a clamped container-unit recipe, then use it while the work is still cheap to change. For context-responsive component design, the artifact should make ownership, constraint, and next action visible without requiring a private explanation.

Success would look like controlled local scaling without unstable hierarchy. If I cannot point to that evidence, I have a direction, not a finished decision.

The implementation move is to make a clamped container-unit recipe part of the working surface. I would use it to answer “Which value should scale?” while scope is still flexible, and “What are safe minimum and maximum?” before code or content becomes expensive to unwind. During QA, “Does zoom remain usable?” and “Is discrete change clearer?” become concrete checks rather than discussion prompts. That sequence turns context-responsive component design into something the team can operate and gives me a specific outcome to report: controlled local scaling without unstable hierarchy.

Preserve semantics through composition

Visual reordering should not create a reading, focus, or speech order that disagrees with the visible card.

Before implementation, I would answer:

  • What is the source order?
  • Does grid placement move meaning?
  • Where does focus travel?
  • Are duplicate labels introduced?

The artifact is a reading-and-focus order check. Its job is to expose the tradeoff early enough that design, engineering, support, or product can disagree with something concrete. The common trap is using CSS order to repair the wide layout; it moves uncertainty downstream and makes the final interface carry a problem the system never resolved.

For me, the useful receipt is consistent meaning across layouts and inputs. That connects a container-owned layout contract using inline-size queries, intrinsic defaults, logical properties, content fixtures, and progressive enhancement to an observable result instead of a process claim.

I would test this with one typical case and one boundary case. The typical case should make “What is the source order?” easy to answer. The boundary should force a decision about “Does grid placement move meaning?” and “Where does focus travel?.” I would record both in a reading-and-focus order check, including the part that stayed unresolved after the first pass. The final check, “Are duplicate labels introduced?,” is where the artifact earns its place: it either supports consistent meaning across layouts and inputs, or it shows exactly why another iteration is needed.

Design media and action behavior

Images, menus, badges, and primary actions need explicit crop, overflow, target, and wrapping behavior at every container state.

I would use these prompts during the working review:

  • What may crop?
  • Which action stays visible?
  • Can a menu replace buttons?
  • Are targets still large enough?

If the team slips into treating the card as text boxes only, the product can still look complete while its operating rule stays ambiguous. I would make a media/action state matrix the shared reference and keep it small enough to update as evidence changes.

The standard is complete interaction quality at every local size. That tells me whether the decision helped the product, not merely whether the document was completed.

The working sequence is small: draft a media/action state matrix, review it against “What may crop?,” implement the narrowest useful path, and then return with evidence for “Which action stays visible?.” I would use “Can a menu replace buttons?” to inspect product consequence and “Are targets still large enough?” to decide whether the result is stable enough to ship. This keeps treating the card as text boxes only visible as a known risk and makes complete interaction quality at every local size the release receipt rather than a hopeful conclusion.

Add progressive enhancement

Use @supports or a sound intrinsic fallback when the product's support promise includes browsers without the chosen container features.

I would pressure-test that decision with four questions:

  • Which browsers matter?
  • Does base layout remain useful?
  • Can media queries assist the wrapper?
  • When can fallback be deleted?

The failure mode here is shipping an empty or broken component outside the enhancement. In reusable product cards that appear in dashboards, sidebars, grids, modals, recommendation rails, and embedded surfaces where viewport width does not describe the space the component actually receives, that can hide the exact boundary a reviewer or teammate needs to understand. My working artifact would be a dated compatibility and fallback note. I want it close enough to the implementation that it can change the work, not created afterward to decorate the story.

The result I would look for is bounded modern CSS adoption. That is a narrower claim than saying the whole system improved, but it is also one I can verify and defend.

In practice, I would put a dated compatibility and fallback note beside the question “Which browsers matter?” before the first implementation review. The next pass would use “Does base layout remain useful?” to test the boundary, then “Can media queries assist the wrapper?” to expose the state most likely to be missed. I would keep “When can fallback be deleted?” for the release check because it asks whether the decision still holds outside the ideal path. The work is ready to move when the artifact can explain the choice and the observed result supports bounded modern CSS adoption.

Test contexts, not screenshots

Visual and interaction tests should render the same card across controlled container widths, content extremes, zoom, localization, focus, and missing media.

The practical review starts here:

  • Which widths represent pressure?
  • What content is longest?
  • Does focus clip?
  • Is horizontal overflow absent?

Those questions keep capturing one desktop and one mobile viewport from becoming the default. I would capture the decision in a container-fixture visual test grid, then use it while the work is still cheap to change. For context-responsive component design, the artifact should make ownership, constraint, and next action visible without requiring a private explanation.

Success would look like evidence that the component is genuinely reusable. If I cannot point to that evidence, I have a direction, not a finished decision.

The implementation move is to make a container-fixture visual test grid part of the working surface. I would use it to answer “Which widths represent pressure?” while scope is still flexible, and “What content is longest?” before code or content becomes expensive to unwind. During QA, “Does focus clip?” and “Is horizontal overflow absent?” become concrete checks rather than discussion prompts. That sequence turns context-responsive component design into something the team can operate and gives me a specific outcome to report: evidence that the component is genuinely reusable.

What I would show in the work

The public version needs evidence from the work itself. For this topic, the first five artifacts I would reach for are:

  • a card context and pressure inventory
  • a wrapper-to-component container contract
  • a query-free stacked card
  • a content-driven threshold note
  • a documented named-container exception

I would not publish all five at equal weight. One should orient the reader, one should reveal the hardest tradeoff, and one should prove the result. The others can live in a downloadable note or appear as supporting frames. That edit matters because a container-owned layout contract using inline-size queries, intrinsic defaults, logical properties, content fixtures, and progressive enhancement becomes harder to understand when every process detail is treated as equally important.

I would also show one rejected direction. The useful version is specific: which option looked attractive, which constraint made it wrong, and what evidence supported the narrower choice. That gives an engineering manager something real to question and keeps the case study from reading like the final answer was obvious from the beginning.

container-query-card.css
# container
.card-slot { container-type: inline-size; }
The slot owns width; the card remains portable and may also query a named container when nesting requires precision.

# base .card { display:grid; gap:1rem; } Source order follows reading order; min-inline-size:0 protects text; logical spacing survives writing modes.

# query @container (min-width: 36rem) Switch to media/content columns, align actions, and use cqi only where scaling has sensible caps.

Figure 4: A small CSS contract supports many placements.

Resource path

The practical follow-up I would build is a container-query card starter with wrapper contract, container name and type, intrinsic baseline, size queries, container units, content variants, accessibility states, fallback, Storybook fixtures, and visual tests. I am treating that as a resource backlog item, not pretending the adjacent downloads below are the same artifact. The related cards cover useful pieces of the workflow today; this specific file should only be published when its examples, fields, and instructions are complete.

The first version should stay concise: context, constraint, decision, evidence, owner, and follow-up. Its value would come from helping someone repeat this exact review, not from adding another generic PDF to the site.

Review checklist

The article-specific review questions are:

  • Where does the card render?
  • Which ancestor owns width?
  • Does text overflow?
  • When does text become unreadable?
  • Can the nearest container work?
  • Which value should scale?
  • What is the source order?
  • What may crop?
  • Which browsers matter?
  • Which widths represent pressure?

I would add two editorial checks before publishing: can a recruiter find the point in the first minute, and can an engineer trace at least one claim to an implementation or production receipt? If either answer is no, the article needs another edit.

Implementation notes

For context-responsive component design, I would write the implementation note before polish. It would name the changed surface, source of truth, owner, failure boundary, and verification path. Those details prevent the principle from floating above the actual code or operational workflow.

The proof signals I care about are specific to this article:

  • controlled local scaling without unstable hierarchy
  • consistent meaning across layouts and inputs
  • complete interaction quality at every local size
  • bounded modern CSS adoption
  • evidence that the component is genuinely reusable

I would choose two or three of those signals for the first release rather than instrumenting everything. The strongest pair usually combines one direct behavior check with one operating check: a route and a data query, a keyboard path and a support state, a handler replay and a reconciliation result, or a migration count and a rendered screen.

The follow-up belongs in the note before shipping. It should say what remains temporary, what evidence would trigger another pass, and who owns that decision. That is how the first version stays intentionally narrow without making the boundary invisible.

Case-study packaging

I would structure the case-study version around the four visual lessons already established:

  • The container contract moves responsiveness closer to the component.
  • Start intrinsic and enhance in layers.
  • Query thresholds should follow content pressure.
  • A small CSS contract supports many placements.

The opening frame explains the product pressure. The middle two show the decision moving through the system. The last frame is the receipt: what was checked, what held, and what remained unresolved. That order lets the reader move from product judgment into implementation detail without reconstructing the whole project first.

I would include one caveat tied to reusable product cards that appear in dashboards, sidebars, grids, modals, recommendation rails, and embedded surfaces where viewport width does not describe the space the component actually receives: a data limit, rollout boundary, unsupported state, external dependency, or result that is still directional. A precise caveat makes the evidence easier to trust because it shows where the claim stops.

The final test is whether the page creates a better conversation. If the artifact helps someone ask a sharper question about product judgment, implementation detail, or release proof in a live interview, it belongs in the story.

Interview angle

In an interview, I would explain this through a container-owned layout contract using inline-size queries, intrinsic defaults, logical properties, content fixtures, and progressive enhancement. The story should start with the product pressure, then move into the system constraint, the artifact, and the proof. That order keeps the answer grounded. It also gives the interviewer several places to go deeper: data, frontend architecture, design systems, support, migration, accessibility, or release process.

The strongest version of the answer includes a tradeoff. I want to be able to say what I chose, what I left alone, and how I knew the work helped. That is more credible than presenting every project as a clean win.

The hiring signal

A container-query card is a hiring signal because it shows I can design component behavior around its actual layout context and content rather than accumulating route-specific viewport exceptions.

That is the level I want this site to communicate. The work should show taste, but it should also show operating judgment. It should make me look like someone who can enter a real product system, understand the messy middle, ship the useful version, and leave enough proof for the next person to trust it.

Companion artifacts

Use this after reading.

Practical downloads and templates that turn the article into something you can bring into a product review, implementation pass, or agent workflow.

DownloadJun 2026

Front-End State Recipes

Reusable recipes for optimistic actions, loading, empty, error, data-transition, and disabled-control states.

FrontendStatesUX
View details
DownloadJun 2026

Design System Contribution Pack

A contribution brief, drift diagnosis, escape-hatch rules, and component-docs template for product teams.

Design systemsComponentsDocs
View details
DownloadJun 2026

UI PR Risk Review Checklist

A merge-readiness checklist for product intent, states, accessibility, visual durability, and UI implementation risk.

UI reviewQAFrontend
View details