CSS Grid turns two-dimensional layout from a puzzle into a few lines of code. Rows and columns, gaps, alignment — all declared in one place. If you have ever fought with floats or nested flexbox wrappers to build a page layout, Grid is the tool that ends that fight.

The core idea is simple: you declare a grid on a container, then place children into it. Two columns and a gap is three lines:

.layout { display: grid; grid-template-columns: 250px 1fr; gap: 24px; } 

The 1fr unit means "one fraction of the free space". A sidebar of 250px and a main area that takes the rest — no math, no calc, no media-query juggling for the basic case. Need three equal columns? grid-template-columns: repeat(3, 1fr).

Grid really shines when a layout has both rows and columns. A classic page shell — header, sidebar, content, footer — is one declaration:

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

Named areas read like a sketch of the page, and rearranging the layout later means editing the strings, not the HTML.

For responsive grids, auto-fit with minmax is the pattern to learn first. This card grid fits as many 250px cards per row as the screen allows, and stretches them to fill the row:

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; } 

No breakpoints, no JavaScript, no framework. The browser does the work.

Two mistakes beginners make: first, using Grid for everything — a single row of buttons is still a flexbox job. Grid is for two-dimensional layouts; flexbox is for one-dimensional rows or columns. Second, forgetting gap and adding margins to grid children instead, which breaks alignment.

Ways to extend it: try grid-auto-flow: dense to fill holes in a masonry-style layout, experiment with place-items: center for the easiest centring in CSS, and combine Grid for the page shell with flexbox inside each area. Once you think in rows and columns instead of nested divs, most layouts take minutes.