# Subgrid Card Alignment

> Cards side by side whose titles, text and buttons line up across the row, thanks to subgrid.

- Category: [CSS Layouts](https://copy-css.com/category/layouts)
- Tags: subgrid, grid, cards, align, equal height
- Live preview: https://copy-css.com/snippets/subgrid-cards
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<div class="sub-cards">
  <article>
    <h3>Fast</h3>
    <p>Pages load in under a second.</p>
    <a href="#">Learn more</a>
  </article>
  <article>
    <h3>Secure by default</h3>
    <p>Encrypted at rest and in transit, with audit logs.</p>
    <a href="#">Learn more</a>
  </article>
</div>
```

## CSS

```css
.sub-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  font-family: system-ui, sans-serif;
}

/* Each card spans 3 rows and shares them with its neighbours */
.sub-cards > * {
  display: grid;
  grid-row: span 3;
  grid-template-rows: subgrid;
  row-gap: 10px;
  padding: 16px;
  border: 1px solid #bbf7d0;
  border-radius: 14px;
  background: #fff;
}

.sub-cards h3 {
  margin: 0;
  color: #14532d;
  font-size: 17px;
  line-height: 1.25;
}

.sub-cards p {
  margin: 0;
  color: #4b5563;
  font-size: 14px;
  line-height: 1.45;
}

.sub-cards a {
  align-self: end;
  padding: 9px;
  border-radius: 8px;
  background: #16a34a;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}
```

## Notes

- This CSS Subgrid Card Alignment is 44 lines of pure CSS (0.8 KB) with no JavaScript and no dependencies. It uses subgrid and CSS Grid.
- subgrid: Chrome 117+, Safari 16+, Firefox 71+.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
