Skip to content
Back to Concepts
CSS UniverseTrack 3: Flexbox & GridCSS Grid
2-Dimensional Layout ArchitectureCore Concept 11

CSS Grid Layout

The king of 2D layouts. Coordinate rows and columns simultaneously with the revolutionary fr unit, minmax(), and the magic responsive one-liner.

1. The Core Mental Model

When to Use Flexbox vs When to Use Grid

Flexbox: 1-Dimensional (Content-First)

Use Flexbox when you want items to sit in a single row or column, and let the content size dictate where each item lands.
Best for: Navbars, button groups, modal footers, tag lists.

CSS Grid: 2-Dimensional (Layout-First)

Use Grid when you have both horizontal columns and vertical rows that must line up strictly like a spreadsheet.
Best for: Full page layouts, dashboard bento grids, card directories.

2. The Magic Responsive Formula

`repeat(auto-fit, minmax(250px, 1fr))`

The single most famous CSS Grid snippet. It creates a completely responsive grid of cards with zero media queries:

.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
}
/* How it works: - minmax(250px, 1fr): Each card is at least 250px wide, but stretches to fill free space. - auto-fit: Automatically wraps into 4, 3, 2, or 1 column depending on screen width! */
3. Live Grid Track Studio

Adjust Columns & Fr Track Sizing

Card #1
Card #2
Card #3
Card #4
Card #5
Card #6
4. Full Grid Workbench

Interactive Grid Visualizer

Interactive Lab

Advanced CSS Grid Studio

Experiment with 2D fractional tracks, auto-fit/auto-fill, dense packing, item column/row spanning, and line number coordinates.

Track Template Presets
2D Alignment & Flow
grid-auto-flow
Item 1 SpanningClick card to select
grid-column span2
grid-row span1
Grid Columns: repeat(3, 1fr)Auto-flow: row
Item 1
col: span 2
Item 2
Item 3
row: span 2
Item 4
Item 5
Item 6
col: span 2

Click any block to adjust its grid-column and grid-row spanning.

.grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; justify-items: stretch; align-items: stretch; grid-auto-flow: row; } /* Selected Child (Item 1) */ .item-1 { grid-column: span 2; }
Next in Track 3

12. CSS Subgrid

Align nested card titles, buttons, and content directly to parent grid rows.

Continue to CSS Subgrid