Development

Building with Modern CSS Grid

A comprehensive look at CSS Grid and how it's transformed the way we approach layout design in modern web development — from simple pages to complex applications.

James Platt

James Platt

February 5, 2026 · 6 min read

6 min read
Building with Modern CSS Grid

Before CSS Grid, building complex web layouts required creative hacking — floats, inline-blocks, positioning tricks, and eventually Flexbox workarounds. We shipped production code that worked, but none of us were particularly proud of it. CSS Grid changed everything. For the first time, we had a genuine two-dimensional layout system built directly into the browser.

The specification has been around since 2017, but Grid's adoption has accelerated significantly in recent years as browser support solidified and developers started pushing beyond basic use cases. Today, CSS Grid is capable of layouts that would have been unthinkable without JavaScript just a few years ago.

Understanding the Grid Container

Everything in CSS Grid starts with the container. When you apply display: grid to an element, you create a grid formatting context. The immediate children of that element become grid items. From there, you define columns and rows using grid-template-columns and grid-template-rows.

The fr unit is Grid's most powerful contribution to the CSS lexicon. It represents a fraction of the available space in the grid container. grid-template-columns: 1fr 2fr 1fr creates three columns where the middle column is twice as wide as the others — and it recalculates automatically as the viewport changes.

Placing Items with Precision

Grid's placement model gives you granular control over where items land. You can explicitly place items using line numbers, named grid areas, or let the auto-placement algorithm handle it. Named areas, defined with grid-template-areas, are particularly powerful for semantic, readable layouts:

"CSS Grid is the first layout system purpose-built for two-dimensional design. Everything before it was a clever workaround."

The grid-area property on child elements references these named zones, creating a visual map of your layout directly in your CSS. When you look at the grid template definition, you can see the layout at a glance — no mental gymnastics required.

Responsive Grids Without Media Queries

One of Grid's more remarkable capabilities is building genuinely responsive layouts with minimal media query intervention. The combination of auto-fill or auto-fit with minmax() creates grids that reflow intelligently based on available space.

grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)) — this single declaration creates a responsive column layout that automatically adjusts the number of columns based on the container width. No breakpoints. No JavaScript. Just CSS doing exactly what CSS was meant to do.

CSS Grid vs Flexbox

The Grid versus Flexbox debate misses the point — they're complementary tools designed for different jobs. Flexbox excels at one-dimensional layouts: distributing items along a single axis, handling alignment, and managing flexible sizing in a row or column. Grid shines in two-dimensional layouts where you need control over both axes simultaneously.

The practical rule: reach for Flexbox when you're laying out items in a line. Reach for Grid when you're designing a page-level structure or a component that needs to maintain alignment across both rows and columns. Use them together — a Grid for the page shell, Flexbox for components within each cell.

Tags

James Platt

James Platt

Web Developer

James is a Microsoft-qualified C# .NET developer with extensive experience building robust, data-rich web applications. He writes about web development, software architecture, and best practices at JP Codes.

Read more about James

More articles