CSS Subgrid Card Alignment

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

  • subgrid
  • grid
  • cards
  • align
  • equal height
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
.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;
}

About this CSS Subgrid Card Alignment

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. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.

CSS features used

Customize it

The colors in this snippet. Search and replace them to match your brand:

  • #bbf7d0
  • #fff
  • #14532d
  • #4b5563
  • #16a34a

How to use this subgrid card alignment

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .sub-cards class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).

Building with an AI tool?

“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.

Feedback