⊞CSS Grid Complete Guide
← Real-World Layouts

πŸƒ Responsive Card Grid

The most-used CSS Grid pattern: a responsive grid of cards that automatically adjusts the number of columns based on available width β€” with zero media queries. Based on the RAM technique: Repeat, Auto-fill, Minmax.

repeat(auto-fill, minmax())repeat(auto-fit, minmax())subgridgrid-template-rows

1. Product Card Grid

A realistic e-commerce product grid. Cards are at least 180px wide and grow to fill available space. On wide screens: 4+ columns. On narrow: 1 column. No media queries.

Live Demo
πŸ‘ŸBest Seller
Sneakers
$89
Add to Cart
πŸ‘œNew
Handbag
$149
Add to Cart
⌚Premium
Watch
$299
Add to Cart
πŸ•ΆοΈ
Sunglasses
$65
Add to Cart
🧒Sale
Cap
$35
Add to Cart
πŸ’Limited
Ring
$199
Add to Cart
🧳
Luggage
$220
Add to Cart
πŸ₯ΏTrending
Flats
$79
Add to Cart
CSS
.products {
  display: grid;
  grid-template-columns:
    repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.5rem;
}

.card {
  background: white;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  overflow: hidden;
  /* No explicit width needed! */
}
πŸ’‘ resize your browser window β€” the grid adjusts automatically without any @media queries!

2. auto-fill vs auto-fit with Few Items

With fewer items than columns fit, auto-fill preserves empty columns (items stay at min-width), while auto-fit collapses empty tracks so items stretch to fill the row.

Live Demo
auto-fill: 3 items stay at ~180px (empty columns visible)
πŸ‘ŸBest Seller
Sneakers
$89
Add to Cart
πŸ‘œNew
Handbag
$149
Add to Cart
⌚Premium
Watch
$299
Add to Cart
auto-fit: 3 items stretch to fill full row
πŸ‘ŸBest Seller
Sneakers
$89
Add to Cart
πŸ‘œNew
Handbag
$149
Add to Cart
⌚Premium
Watch
$299
Add to Cart
CSS
/* auto-fill: keeps empty track placeholders */
.fill {
  grid-template-columns:
    repeat(auto-fill, minmax(200px, 1fr));
}

/* auto-fit: collapses empty tracks */
.fit {
  grid-template-columns:
    repeat(auto-fit, minmax(200px, 1fr));
}

3. Equal Card Heights with Subgrid

The subgrid problem: cards in a row should have their internal elements (image, title, price, button) aligned across cards β€” even if card content varies in height.

Live Demo
πŸ‘Ÿ
Sneakers
Premium running shoes with extra cushioning
$89Buy
πŸ‘œ
Designer Handbag with a very long product name
Luxury
$149Buy
⌚
Watch
Swiss precision timepiece
$299Buy
CSS
/* Parent: 4 rows for the 4 internal sections */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: auto auto auto auto;
}

.card {
  display: grid;
  grid-row: span 4;        /* span all 4 row tracks */
  grid-template-rows: subgrid; /* use parent rows! */
}
/* Result: image/title/desc/price align across all cards */
πŸ’‘ Subgrid is the correct solution for aligned card internals. Without it, each card manages its own rows independently, causing misalignment.

4. Featured Card Variant

Make selected cards larger by giving them a column or row span. The rest of the grid flows naturally around them.

Live Demo
⭐FeaturedOur best-selling item this season
πŸ‘œHandbag$149
⌚Watch$299
πŸ•ΆοΈSunglasses$65
🧒Cap$35
πŸ’Ring$199
🧳Luggage$220
CSS
.grid {
  display: grid;
  grid-template-columns:
    repeat(auto-fill, minmax(160px, 1fr));
  grid-auto-rows: 1fr; /* equal row heights */
  gap: 1rem;
}

.card--featured {
  grid-column: span 2; /* 2Γ— wider */
  grid-row: span 2;    /* 2Γ— taller */
}