CSS

CSS Grid: A Practical Guide to Picking the Right Layout Technique

By Ken Key Aug 5, 2024 4 min read Updated Oct 16, 2026

CSS Grid: A Practical Guide to Picking the Right Layout Technique
The short answer

Use Grid when you're placing items in rows and columns at the same time. Use Flexbox when you're aligning items along one axis, like a nav bar or a row of cards. That single question settles most layout decisions before you write any CSS.

Part of the complete web design guide.

On this page

Most people searching for “the best CSS Grid technique” are really asking a different question: which layout tool should I reach for on this specific piece of UI? There is no single best technique. There is a right tool for the shape of the problem in front of you, and the sooner you stop treating Grid as a replacement for Flexbox (or vice versa), the faster your layouts get simpler.

I’ve been building sites for a long time, mostly for small businesses and agencies around Commack and the rest of Long Island, and the layout questions I get are almost always the same handful. So here’s the honest breakdown.

Grid vs. Flexbox: Stop Picking Sides

The rule I actually use: Grid handles two dimensions, Flexbox handles one. If you’re placing things into rows and columns at the same time, use Grid. If you’re lining things up along a single axis (a nav bar, a row of cards, a stack of form fields), use Flexbox.

That’s it. That’s the decision. Everything else is detail.

/* One axis: Flexbox */
.nav {
 display: flex;
 align-items: center;
 gap: 1.5rem;
}

/* Two axes: Grid */
.dashboard {
 display: grid;
 grid-template-columns: 240px 1fr;
 grid-template-rows: auto 1fr;
 gap: 1rem;
}

People overthink this. If you find yourself nesting three Flexbox containers to fake a grid, you wanted Grid. If you’re writing grid-template-columns: repeat(12, 1fr) to lay out a single row of buttons, you wanted Flexbox.

The Grid Techniques Worth Knowing in 2026

1. auto-fit + minmax() for responsive card grids

This is the one pattern that eliminates most media queries from your stylesheet. It’s been around for years and it’s still the best answer for “I want cards that wrap and fill the space.”

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

Cards sit at a minimum of 280px and stretch to fill whatever space is left. No breakpoints. The browser does the math. Swap auto-fit for auto-fill when you want empty tracks to stay reserved instead of collapsing.

2. Named grid areas for page-level layout

For a whole page shell, named areas beat line numbers for readability. You can see the layout in the CSS.

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

.page > header { grid-area: header; }
.page > aside { grid-area: sidebar; }
.page > main { grid-area: main; }
.page > footer { grid-area: footer; }

@media (max-width: 720px) {
 .page {
 grid-template-areas:
 "header"
 "main"
 "sidebar"
 "footer";
 grid-template-columns: 1fr;
 }
}

Note the 100dvh instead of 100vh. On mobile browsers, vh lies to you because of the collapsing address bar. dvh is the dynamic viewport height and it behaves the way you expect.

3. Subgrid for aligning nested content

Subgrid is the technique people sleep on. It’s been supported in all major browsers since late 2023, so in 2026 there’s no excuse. It lets a child grid inherit the track sizing of its parent, which solves the classic “my card titles don’t line up because the descriptions are different lengths” problem.

.cards {
 display: grid;
 grid-template-columns: repeat(3, 1fr);
 gap: 1.5rem;
}

.card {
 display: grid;
 grid-row: span 3;
 grid-template-rows: subgrid;
}

/* Now every card's title, body, and footer align
 across the whole row, no fixed heights needed. */

Before subgrid, you either set a min-height and prayed, or you reached for JavaScript. Neither was good. Subgrid just fixes it.

4. grid-template-columns with min-content and max-content

These keywords are underused. They let content size its own track.

.toolbar {
 display: grid;
 grid-template-columns: max-content 1fr max-content;
 align-items: center;
 gap: 1rem;
}

The buttons on the ends take exactly the width they need. The middle takes everything else. This is a clean pattern for toolbars, table rows, and list items with trailing actions.

Things That Still Trip People Up

  • Gap vs. margin. Use gap. It doesn’t add space to the outer edges and it works in both Grid and Flexbox now.
  • Grid doesn’t need a container width. You don’t have to wrap everything in fixed pixel widths. Let the tracks do the work.
  • Don’t use Grid for everything. A single column of stacked text is just display: block. Adding Grid there is noise.
  • Accessibility matters more than the layout. Grid and Flexbox don’t change reading order for screen readers, but order and grid-area can create a visual order that fights the DOM order. Keep them in sync or you’ll confuse keyboard users.
  • Test on real devices. Responsive grid behavior in a desktop browser’s device emulator is close, but not identical to a real phone. If you’re doing this kind of work for clients and want it done right, a Long Island web design approach that includes real device testing saves you a rewrite later.

My Actual Default Stack

If you want the short version, here’s what I reach for without thinking:

  • Page shell: Grid with named areas.
  • Card collections: Grid with auto-fit and minmax().
  • Aligned card internals: subgrid.
  • Nav bars, button rows, form fields: Flexbox.
  • Anything single-axis and simple: plain block or inline layout.

That covers maybe 95% of the layouts on a typical business site. The remaining 5% is where you get creative, and by then you’ll know why you’re choosing what you’re choosing.

FAQ

Should I use Grid or Flexbox for a navigation bar?

Flexbox. A nav bar is a single row of items, which is one axis. Grid works too, but Flexbox is the simpler fit and handles wrapping and alignment with less code.

Is subgrid safe to use in 2026?

Yes. It’s supported in current Chrome, Edge, Firefox, and Safari. If you still support very old browsers, provide a fallback with fixed row heights, but for most projects subgrid is fine to use directly.

Do I still need media queries if I use auto-fit and minmax()?

Less often, but not never. Those functions handle how many columns fit, but they don’t change font sizes, spacing scales, or the order of content. For those, you still want a breakpoint or two.

Have a project like this?

I do Long Island web design for Long Island businesses. If you need this done right, let’s talk.