CSS Flexbox vs Grid — When to Use Each

Flexbox lays out items along a single axis; Grid lays out items in two dimensions (rows and columns). Learn which layout model fits which situation.

Published September 21, 2026

Use Flexbox for one-dimensional layouts (a row or a column of items) and Grid for two-dimensional layouts where rows and columns must line up. Many pages use both.

The concept

Flexbox lays items along a single axis and lets them grow, shrink and wrap based on their content. It shines for navbars, button groups and centring.

Grid defines rows and columns first and then places items into cells. It is built for page layouts, galleries and dashboards.

Axes

Flexbox: [ A ][ B ][ C ] one direction
Grid: [ A ][ B ][ C ]
[ D ][ E ][ F ] rows AND columns

Practical examples

Flexbox navbar

.nav { display: flex; gap: 1rem; justify-content: space-between; align-items: center; }

Responsive card grid

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

Holy-grail page layout

.page { display: grid; grid-template-areas: 'h h' 's m' 'f f'; grid-template-columns: 220px 1fr; }

Combine them

.card { display: flex; flex-direction: column; }

Common mistakes

  • Using Flexbox with fixed widths to fake a grid.
  • Forgetting that flex items shrink; set flex-shrink or min-width.
  • Nesting grid unnecessarily when a single declaration works.

Key takeaways

  • Flexbox = one dimension, content-driven.
  • Grid = two dimensions, layout-driven.
  • They combine well.

FAQ

Is Grid replacing Flexbox?

No; they solve different problems.

Browser support?

Both are supported in all modern browsers.

More CSS articles