⊞CSS Grid Complete Guide

Spanning Rows & Columns

Grid items can span across multiple tracks in either direction. This is how you create complex, magazine-style layouts where some items are larger than others.

grid-column: span Ngrid-row: span Ngrid-columngrid-row

1. Column Spanning

Make an item span multiple columns. The item occupies multiple column tracks while other items flow around it.

Live Demo
Spans all 3 columns
Spans 2 cols
1
1
Spans 2 cols
CSS
.header { grid-column: span 3; } /* full width */
.wide   { grid-column: span 2; } /* 2 of 3 cols */
.normal { /* no span β€” just 1 column */ }

2. Row Spanning

Make an item taller by spanning multiple rows. This is the key technique for creating sidebar layouts and featured image cards.

Live Demo
Spans 3 rows tall
item
item
Spans 2 rows
item
item
item
CSS
.container {
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 70px; /* consistent row heights */
}
.tall-3  { grid-row: span 3; }
.tall-2  { grid-row: span 2; }

3. Spanning Both Axes

An item can span multiple columns AND multiple rows simultaneously, creating a larger grid cell. This is perfect for featured content areas.

Live Demo
2Γ—2 Featured
col span 2, row span 2
item
item
item
item
col span 2
item
item
CSS
.featured {
  grid-column: span 2; /* 2 columns wide */
  grid-row:    span 2; /* 2 rows tall    */
}
/* creates a 2Γ—2 cell in the grid */

4. Magazine-Style Layout

Combining column and row spanning creates rich editorial layouts. Use explicit placement + spanning together.

Live Demo
πŸ–ΌοΈ Hero Image
cols 1-3, rows 1-3
Story 1
Story 2
Wide Story
Short
Short
Short
Short
CSS
.container {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: 80px 80px 80px;
}
.hero  { grid-column: 1 / 3;   grid-row: 1 / 3; }
.wide  { grid-column: 3 / 5;   grid-row: 2;     }
πŸ’‘ This is the foundation of every newspaper/magazine layout built with CSS Grid. Combine explicit placement with span for maximum flexibility.

5. Pinterest-Style Variable Heights

CSS Grid doesn't natively support masonry layout (random heights filling gaps), but you can approximate it with row spans. True masonry requires JavaScript or the CSS masonry spec (in development).

Live Demo
tall
medium
short
short
tall
medium
medium
short
CSS
.container {
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 40px; /* base unit */
  grid-auto-flow: dense; /* fill gaps (see Dense topic) */
}
.tall   { grid-row: span 3; }
.medium { grid-row: span 2; }
.short  { grid-row: span 1; }
πŸ’‘ For true auto-filling masonry (like Pinterest), combine row spanning with grid-auto-flow: dense. The Dense Packing topic shows this in detail.