# Container Query Card

> A card that switches from stacked to side by side based on its container’s width, not the viewport.

- Category: [CSS Layouts](https://copy-css.com/category/layouts)
- Tags: container queries, @container, responsive, card, component
- Live preview: https://copy-css.com/snippets/container-query-card
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<div class="cq-wrap">
  <article class="cq-card">
    <div class="cq-media"></div>
    <div>
      <h3>Container queries</h3>
      <p>This card lays itself out by its own width.</p>
    </div>
  </article>
</div>
```

## CSS

```css
.cq-wrap {
  container-type: inline-size;
}

.cq-card {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid #e0e7ff;
  border-radius: 14px;
  background: #fff;
  font-family: system-ui, sans-serif;
}

.cq-media {
  min-height: 72px;
  border-radius: 10px;
  background: linear-gradient(135deg, #a5b4fc, #6366f1);
}

.cq-card h3 {
  margin: 0 0 4px;
  color: #1e1b4b;
  font-size: 15px;
}

.cq-card p {
  margin: 0;
  color: #64748b;
  font-size: 13px;
  line-height: 1.4;
}

/* Side by side once the container is wide enough */
@container (min-width: 300px) {
  .cq-card {
    grid-template-columns: 96px 1fr;
    align-items: center;
    gap: 14px;
  }

  .cq-media {
    aspect-ratio: 1;
  }
}
```

## Notes

- This CSS Container Query Card is 45 lines of pure CSS (0.7 KB) with no JavaScript and no dependencies. It uses linear gradients, CSS Grid, container queries and aspect-ratio.
- container queries: Chrome 105+, Safari 16+, Firefox 110+.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
