Skip to content

CSS Grid vs Flexbox: Choosing the Right Layout Tool

Grid or Flexbox? Use the decision rule, then see what 3 browser engines measured: long-word overflow, last-row stretch and layout cost at 8,000 items.

· · 16 min read

Updated: October 16, 2026

CSS Grid two-axis layout beside Flexbox single-axis layout, with layout cost measured in Chromium, Firefox and WebKit

Quick Take

Use Grid for two-dimensional layouts where you control rows and columns simultaneously; use Flexbox for one-dimensional component layouts like navbars, button groups, and card rows. You'll use both in every project, the choice is about which dimension you're managing.

CSS Flexbox is a one-dimensional layout module that arranges items along a single axis, row or column, and handles component-level alignment. CSS Grid is a two-dimensional layout module that manages rows and columns simultaneously. CSS Flexbox arranges items along a single axis (row or column) and handles component-level alignment: navigation bars, button groups, centered content, tag lists, and vertically stacked card layouts. CSS Grid is a two-dimensional layout system, it manages rows and columns simultaneously and suits page-level structure: header/sidebar/main/footer shells, image galleries, and dashboard grids where items span multiple columns. Flexbox has 99%+ global browser support in 2026; Grid has 97%+. They work together, not against each other. The practical decision rule: if layout runs in one direction only, use Flexbox. If you need control in both directions at once, or need explicit item placement (like grid-column: span 2), use Grid. Most production UIs use Grid for the outer shell and a flex container inside each region for alignment.

Developers argue about this constantly. Some teams ban Grid entirely because "Flexbox does everything" and others go the opposite direction. Both positions are wrong. These two tools were built for different jobs, and knowing which one to reach for first saves real time.

The frustrating part is that picking wrong rarely fails loudly. It fails as a layout that works at every width you checked and collapses at one you did not, and by then the wrong container is three components up.

What Problem Does Flexbox Solve?

Flexbox excels at distributing items along a single axis. It's "one-dimensional" - you work in either a row or a column, not both at once. It became the default for component-level alignment because the math it handles automatically used to require float hacks and clearfix.

/* Classic navbar - items in a row with space between */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem;
}

/* Push the last button to the far right */
.navbar__actions {
  margin-left: auto;
}

The mental model for Flexbox: you have a flex container and its child elements inside. You set display: flex on the container, then control alignment properties like justify-content and align-items on both axes. That's it. When developers first picked it up around 2016, it typically replaced a huge share of float-based layout CSS almost overnight. Per MDN Web Docs, Flexbox reached broad browser support years before Grid did, which is part of why it became the default reflex for any alignment problem, even the two-dimensional ones it was never really designed to solve well.

Hand-drawn wireframe sketches of app screen layouts on paper
Photo by Hal Gatewood on Unsplash

What Problem Does CSS Grid Solve?

Grid is two-dimensional. You define rows and columns using grid-template-areas or explicit track sizes, then place items anywhere in that matrix. It's the right tool when layout in both directions matters simultaneously.

/* Classic page shell with sidebar */
.page {
  display: grid;
  grid-template-columns: 250px 1fr;
  grid-template-rows: 64px 1fr 48px;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  min-height: 100dvh;
}

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

Try doing this cleanly with Flexbox. You can't - you'd need nested Flexbox containers with carefully managed widths and some fragile height calculations. Grid solves it in 10 lines. According to MDN's own comparison of the two specs, Grid was designed from the outset to manage both axes at once, while Flexbox's single-axis model means a second dimension has to be faked with wrapper elements and manual width math, a workaround that breaks the moment content changes height unexpectedly.

When Should You Use Flexbox?

Reach for Flexbox when you have a list of items that need to line up along a single direction. These patterns are Flexbox territory:

  • Navigation bars and tab lists
  • Button groups and icon-with-label pairs
  • Card content layout (image + title + description stacked vertically)
  • Centering a single element inside a container
  • Distributing items with equal gaps
/* Tag list that wraps naturally */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Vertical card layout */
.card {
  display: flex;
  flex-direction: column;
}

.card__body {
  flex: 1; /* grows to fill available space */
}

.card__footer {
  margin-top: auto; /* pins to bottom */
}

The flex: 1 and margin-top: auto pattern belongs in almost every card component. It keeps the footer pinned to the bottom regardless of content height, without knowing the card height in advance. Centering is the other job people reach for Flexbox on, though Grid's place-items: center is shorter; I walk through every approach in centering a div in CSS. Five properties carry most of the work: display: flex, flex-direction, justify-content, align-items, and gap, a short enough list to memorize rather than look up each time.

When Should You Use CSS Grid?

Reach for Grid when the layout has meaningful structure in both dimensions. These patterns belong to Grid:

  • Full page layouts (header, sidebar, content, footer)
  • Image galleries and media grids
  • Dashboard card grids with varying column spans
  • Form layouts with label and input alignment
  • Any layout where you want items to align across rows
/* Responsive card grid - no media queries needed */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

That repeat(auto-fill, minmax(280px, 1fr)) pattern is one of CSS's most useful features for responsive layout. Cards automatically reflow from one column to many as space grows. No JavaScript. No breakpoints required. I pull the whole pattern apart, knob by knob, in responsive CSS grid without media queries, including the auto-fit versus auto-fill gotcha that trips up almost everyone.

Grid also has an answer for the one thing nested layouts always got wrong: alignment across separate grids. When card titles and prices refuse to line up row to row, CSS subgrid is the fix, and it's been Baseline in every major browser since late 2023.

For the design-side decisions behind these layouts - when bento grids beat traditional cards, how many tiles a dashboard should display before cognitive load flips negative, and where Subgrid changes the alignment math - see CSS Layout Patterns in 2026 on Art of Styleframe. It's the same problem space approached from the design end of the pipeline.

Placing Items Explicitly

Grid also lets you place specific items in specific cells, which Flexbox simply can't do:

/* Featured article spans two columns */
.article-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.article-grid__featured {
  grid-column: span 2;
}
A 3D illustration of a design tool interface with vector pen, layers, and a color picker
Photo by Resource Database on Unsplash

What Is the Practical Decision Rule?

Here's the rule that actually holds up:

One direction only? Use Flexbox. Two directions, or explicit placement? Use Grid.

When I read this rule back against the layouts on this site, the one place it needed a tiebreaker was the topics card grid (its styles have a .topic-span-2 class that does grid-column: span 2): it reads as one direction until a card has to span two columns, and that single requirement is what makes it Grid. If you find yourself reaching for flex-basis percentages to line items up with the row above, you have already left Flexbox's job description.

Layout question One axis or two? one direction two directions Flexbox Navbar, button rows, stacked lists Need explicit placement? grid-area / grid-row no, just sizing yes Grid (auto-fit + minmax) Grid (template-areas)

When you're unsure, start with Flexbox. If you find yourself adding nested Flexbox containers with flex-wrap to fake grid-like behavior, that's the sign to switch to Grid. A responsive layout built with Grid's auto-fill is almost always cleaner than the Flexbox workaround.

How to decide in practice:

  1. Sketch the layout and ask whether it needs control in one direction or two.
  2. If one direction, reach for Flexbox first, it is simpler for the common cases.
  3. If you catch yourself nesting Flexbox containers to fake row/column alignment, switch to Grid.
  4. Use both together: Grid for the page shell, Flexbox for alignment inside each region.

They also stack well. A common real-world pattern:

/* Grid for the page skeleton */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 60px 1fr;
}

/* Flexbox inside each cell for alignment */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

Outer structure with Grid. Inner alignment with Flexbox. This combination handles the majority of real UI layouts without reaching for any third tool.

Where do Grid and Flexbox actually behave differently?

The decision rule above is about intent. It says nothing about what the two do when content misbehaves, and that's where layouts break in production. So I measured it. Playwright 1.62.1 drove Chromium 151.0.7922.34, Firefox 153.0 and WebKit 26.5 on an Apple M1, and every number below is read back from real layout with getBoundingClientRect() and scrollWidth, not worked out from the CSS. Each group ran twice in fresh browsers. The script asserts all of the layout results (163 checks), so a browser release that changes an answer fails the run.

Does 1fr protect you from a long word better than flex: 1?

No. This is the test I'd run before believing any claim that Grid is sturdier. Three columns in a 600 px container, a 634 px unbreakable word in the middle one:

Layoutleft / middle / right pxcontainer overflow px
flex: 148 / 634 / 48130
grid 1fr 1fr 1fr48 / 634 / 48130
flex: 1 + min-width: 0200 / 200 / 200234
grid minmax(0, 1fr)200 / 200 / 200234
flex: 1 + overflow: hidden200 / 200 / 2000
flex: 1 + overflow-wrap: break-word48 / 634 / 48130
flex: 1 + overflow-wrap: anywhere200 / 200 / 2000

flex: 1 and grid 1fr produce the same three widths to 0.01 px. Both treat a track or item as no smaller than its min-content size, so the word forces the middle one to 634 px and squeezes its neighbors to the width of "short". Same blowout, same engines, same numbers. The popular fix, min-width: 0 or minmax(0, 1fr), gives you three tidy 200 px columns, and then the word pokes 234 px out of the container because nothing told it to break. That's the row people miss: equal columns, still overflowing.

min-width: 0 and minmax(0, 1fr) equalize the columns but leave the content overflowing; only overflow: hidden, overflow-wrap: anywhere or max-width: 100% actually remove the overflow.

Share this Post on X Bluesky

What removes the overflow? overflow: hidden clips it. overflow-wrap: anywhere lets the word break and, unlike break-word, also lowers the min-content size, so it works with no min-width: 0 at all. break-word leaves the blowout exactly where it was (130 px), which is the single most surprising line in the table.

The unsized image behaves the same way. A 1200x600 image in the middle item gives 48 / 1200 / 48 and 696 px of overflow in both models, and min-width: 0 turns that into 200 / 200 / 200 with 800 px of overflow. Adding max-width: 100% to the image fixes both at once (200 / 200 / 200, zero overflow). One flex-only trap showed up here: with flex: 1 1 auto and that same max-width: 100% image, the middle item came out 484 px wide against 58 px for its neighbors. The grid layouts I tested kept the same image at 200 px.

All three engines agreed within about 2 px, and the gap is font metrics: the word is 633.7 px in Chromium and WebKit and 635.8 px in Firefox.

Do flex-wrap and grid auto-fill disagree on columns?

There was no difference in column count. I swept the container from 320 to 1280 px in 8 px steps, 121 widths, with eight items, a 16 px gap and a 200 px minimum. Flex-wrap with flex: 1 1 200px, flex-wrap with flex: 0 0 200px and grid repeat(auto-fill, minmax(200px, 1fr)) produced the same column count at every width, and the same first-row item width for the growing variants, in all three engines. The two models agree until the last row.

At 700 px the eight items fall into rows of 3, 3 and 2. Here's what the last row looks like:

LayoutLast row widths
flex-wrap, flex: 1 1 200px342 + 342 px
flex-wrap, flex: 0 0 200px200 + 200 px
grid auto-fill / auto-fit222.67 + 222.67 px

A growing flex row stretches its two leftover items to 342 px, wider than any item above them. Grid keeps them at the column width. If your design wants a card grid that looks like a grid, that single row is often the deciding factor.

How much slower is Grid for thousands of items?

I forced a layout pass by changing the container's width and reading offsetHeight, ten passes per sample and nine samples per run. Milliseconds per layout at 8,000 items, mean of two passes:

Engineflex-wrapgrid auto-fillflex, one rowgrid, one row
Chromium15.017.44.26.2
Firefox14.526.88.322.5
WebKit25.153.930.657.2

Treat the absolute numbers as noise. The CPU was shared with other jobs the whole time (load average 24 to 36 on 8 cores), and the milliseconds moved by up to a third between complete runs. The ratios held across two complete runs: grid auto-fill cost 1.07x to 1.15x a wrapping flex container in Chromium, 1.77x to 1.84x in Firefox and 2.15x to 2.32x in WebKit. A single grid row cost 1.5x to 2.7x a single flex row everywhere.

So is Grid slow? No. At 500 items every layout in every engine took about 4 ms or less. You'd need an unvirtualized list in the thousands before this matters, and at that point the fix is windowing, not a different display value.

The test has limits. It times layout of plain text items, not paint or real components, and Firefox's timer readings come out on a 0.1 ms grid. Text direction is left to right. The script and its assertions are in the css-grid-flexbox-cross-engine example; npm test reprints every table on your machine.

How Do CSS Grid and Flexbox Properties Compare Side by Side?

Before the pattern list, here's a quick reference for the properties you'll actually use:

Property areaCSS GridFlexbox
AxesTwo (rows + columns simultaneously)One (row or column, not both)
Defining structuregrid-template-columns, grid-template-rowsflex-direction
Item sizingfr units, minmax(), autoflex-grow, flex-shrink, flex-basis
Responsive layoutauto-fill/auto-fit + minmax()flex-wrap
Gapsgap, row-gap, column-gapgap (supported since 2021)
Explicit placementgrid-column, grid-row, grid-areaNot supported, order only
Named regionsgrid-template-areasNot supported
Alignmentjustify-items, align-items, place-itemsjustify-content, align-items
Browser support (2026)97%+ globally99%+ globally

Neither has a meaningful browser support gap anymore. Pick on fit, not on support.

Which Tool Fits Common Layout Patterns?

PatternBest toolWhy
Horizontal nav with logo left, links rightFlexboxSingle axis, space-between
Page shell (header/sidebar/main)GridTwo-dimensional structure
Responsive card gridGridAuto-fill handles reflow
Vertically centered modalFlexbox or GridBoth work; Grid's place-items: center is shorter
Form label + input pairsGridColumn alignment across rows
Chip/tag list with wrapFlexboxNatural wrapping behavior
  • CSS container queries - pair container queries with Grid and Flexbox to make components that respond to their parent's size, not just the viewport
  • CSS to React style converter - paste a Grid or Flexbox rule and get the camelCase style object a React component expects
  • React Server Components - layout decisions affect which components need to be Client Components; understanding the split matters for CSS that works across the server/client boundary
  • React Hooks pitfalls - dynamic layout logic often ends up inside hooks; this covers the state and effect patterns that drive it
  • Recharts - composable chart library (Line, Bar, Pie, Area) built on D3; slots into Grid dashboard layouts and handles responsive sizing via the ResponsiveContainer wrapper
  • React Resizable Panels - when Grid and Flexbox aren't enough, this adds drag-to-resize handles between panels; useful for code editors, dashboards, and split-pane layouts
  • Styleframes design process on Art of Styleframe - design principles that shape the visual decisions behind responsive layouts

Frequently Asked Questions

Can I use Grid and Flexbox together?
Yes, and you should. A common pattern is Grid for the outer page layout (header, sidebar, main, footer) with Flexbox inside each region for aligning items. They're designed to complement each other, not compete.
Does CSS Grid replace Flexbox?
No. Grid handles two-dimensional layouts; Flexbox handles one-dimensional layouts. Both are widely supported: Grid at 97%+ and Flexbox at 99%+ globally as of 2026 per MDN data. Use whichever fits the problem.
Which is better for centering a single item?
Either works, but Flexbox is simpler: set display: flex; align-items: center; justify-content: center on the parent. Grid also works with place-items: center, which is even shorter.
Does min-width: 0 fix a flex or grid item that overflows?
Only half of it. In a 600 px container with a 634 px unbreakable word in the middle item, min-width: 0 (or minmax(0, 1fr) in grid) gives three equal 200 px columns, but the word still sticks out 234 px. overflow: hidden clips it, and overflow-wrap: anywhere breaks the word. All three browser engines behave the same.
Is CSS Grid slower than Flexbox?
Slightly, for very large layouts. In a test of 8,000 items, a grid with auto-fill took about 1.1x the time of a wrapping flex container in Chromium, 1.8x in Firefox and 2.2x in WebKit. At 500 items every layout in every engine took about 4 ms or less, so layout cost should not decide the choice.
When should I use grid-template-areas?
Use grid-template-areas when you have a named layout with distinct regions like a page shell. It makes the visual structure obvious in CSS and is easy to rearrange with media queries by redefining the template.