Container Query Cards
A card that fills in as room allows: image and title first, a line and a button added at 280 px, then the image moving to the left of the text at 400 px. CSS only.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Utilities has 43 effects, including 3 free. Explore the category →
3 usage examples



How it works
The card has two parts: .acw-img, an 80 px indigo gradient band with a pictogram, and .acw-body, holding an h5, a paragraph and a button.acw-btn. In the base rule the paragraph and the button are display: none: in a narrow slot only the image and the title remain, 123 px tall (138 px under 180 px wide, where the demo title wraps onto two lines).
The root .fx-0755-root is the measured container (container: acw-card / inline-size). First threshold, 280 px: the paragraph and the button appear under the title, the card stays vertical. Second threshold, 400 px: .acw-card switches to grid-template-columns: 140px 1fr; the image becomes a 140 px column filling the full height (100 px at least) and the text sits to its right.
Going from one state to the next is immediate: showing an element or changing the column count does not interpolate in CSS. The component ships no script; the button has no action until you give it one.
Accessibility
- No action when small: under 280 px the button is
display: none. It is gone for everyone — mouse, keyboard, screen reader. If the action must stay possible in a narrow slot, put a link on the title, which is always there. - Keyboard: once displayed, the button takes focus with Tab and shows a light 2 px outline (
:focus-visible). - Small button: its label is .7rem (11 px) and its height 20 px; that is under the 24 px recommended for a touch target. Raise
paddingto 8px 14px on a touch screen. - Decorative image: the pictogram carries
aria-hidden="true". If you use a photo that informs, give it a text alternative (role="img"andaria-labelon.acw-img). - Title: it is an
h5; pick the level that suits your page.
Browser compatibility
Container queries and grid, nothing else. Same readings in Chromium 149, Firefox 151 and WebKit 26.5: button hidden at 279 px and shown at 280, one column at 399 px and two at 400; no overflow at 390 px, where the card takes the middle state. Under reduced motion the behaviour is the same since nothing is animated.
Without @container the card stays in its smallest state: image and title, no line and no button, whatever the width. For those browsers, flip the logic — show everything by default and hide inside an @container (max-width: 279px) rule.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0755-root">
<div class="acw-card">
<div class="acw-img">
<svg viewBox="0 0 24 24" aria-hidden="true">…</svg>
</div>
<div class="acw-body">
<h5>Title</h5>
<p>Text shown from 280 px</p>
<button type="button" class="acw-btn">Action</button>
</div>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Thresholds (CSS — @container acw-card (min-width: 280px) and (min-width: 400px)) |
280 and 400 px | Lower the first to 220 px to keep the button in a narrow column; raise the second to 480 px if your text is long. |
Photo (HTML — style="background-image: url(…)" on .acw-img) |
#6366f1 → #8b5cf6 gradient and pictogram |
The photo is cropped and centred (cover); remove the svg then. |
Band height (CSS — .acw-img { height }) |
80 px | 120 px for a real photo; aspect-ratio: 16 / 9 instead of the height for a constant format. |
Image column (CSS — 140px 1fr in the 400 px rule) |
140 px | 1fr 1fr for an image taking half the card. |
Button (CSS — .acw-btn) |
#6063f1, white label, 6 px corners |
Your colours; keep a 4.5 ratio between label and background. |
Card background (CSS — .fx-0755-root, .acw-card) |
#0a0a0f and a 5 % white veil |
On a light page: white root, transparent .acw-card, dark title and text. |
FAQ
style="background-image: url('photo.jpg')" on .acw-img and delete the svg. Cropping (background-size: cover) and centring are already in the CSS; at 400 px the photo fills the left column over the full height.