~/TechPurAI
~/tutorials/css-from-scratch/css-grid-fundamentals
intermediate·part 11 of 22·3 min read

CSS Grid fundamentals: real two-dimensional page layout

Updated Aug 16, 2026CSS

Flexbox, covered in parts 9 and 10, arranges items along one real axis at a time — a row, or a column. CSS Grid is a genuinely different tool: a real, two-dimensional system that controls rows and columns simultaneously. This part uses it for Bright Leaf Coffee's actual homepage-level layout.

The real, genuine difference from Flexbox

text
Flexbox: one-dimensional — you arrange items in a row OR a column,
  and items flow based on their own individual sizing
Grid: two-dimensional — you define a real, explicit row and column
  structure up front, then place items into it directly

Neither is a strict upgrade over the other — they're genuinely suited to different real problems. Part 9's header (a simple row of two items) was correctly a Flexbox job; a real page-level layout with a header, sidebar, main content, and footer — genuine rows and columns at once — is exactly what Grid is built for.

The real homepage layout, in Grid

css
.page-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  min-height: 100vh;
}

.site-header { grid-area: header; }
.sidebar     { grid-area: sidebar; }
.main-content { grid-area: main; }
.site-footer { grid-area: footer; }

grid-template-columns: 240px 1fr defines two real columns — a fixed 240px sidebar, and a second column (1fr, one "fraction unit") that takes up all real remaining space. grid-template-areas is a genuinely readable way to define the real layout visually, in the CSS itself — each quoted string is one row, each word names a real area, and repeating a name across cells (like header spanning both columns) makes that element genuinely span multiple grid cells.

fr: the real unit unique to Grid

css
.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-lg);
}

fr represents a real fraction of the available space in the grid container, after any fixed-size tracks (like the 240px sidebar above) are subtracted. Three equal 1fr columns split the real remaining space evenly — genuinely simpler than the older, real percentage-based math (33.333% with real, careful gap compensation) that equivalent layouts required before Grid existed.

repeat(): a real, genuine shorthand for repetitive tracks

css
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-lg);
}

repeat(3, 1fr) is functionally identical to writing 1fr 1fr 1fr — genuinely more concise, and it becomes a real, meaningful difference once combined with auto-fit or auto-fill, covered in part 12's real responsive grid.

Why it matters

Notice grid-template-areas reads almost like real ASCII art of the actual layout — this is a genuine, deliberate design goal of Grid, not a coincidence. A new team member (or a future version of the same real developer) can look at the area definition and understand the actual page structure at a glance, without mentally simulating how a series of nested Flexbox rows and columns would combine to produce the same layout.

grid-column and grid-row: real, direct placement

css
.featured-product {
  grid-column: 1 / 3;
  grid-row: 2;
}

Beyond named areas, items can be placed by real, explicit line numbers — grid-column: 1 / 3 spans from grid line 1 to grid line 3, covering two real columns. This is genuinely useful for a one-off placement (a single featured item spanning multiple columns) that doesn't warrant defining an entire named area just for it.

Next: CSS Grid deep dive — auto-fit, minmax(), and a genuinely responsive product grid that needs zero media queries to reflow.

VK

Vijay Kumar

Founder of TechPurAI — writing hands-on tutorials and honest tool breakdowns.

LinkedIn ↗
← previous10. Flexbox deep dive: flex-wrap, grow, and shrink for the real subscription cardsnext →12. CSS Grid deep dive: a real responsive product grid with zero media queries