I used to Google "css grid vs flexbox" at the start of every new layout. Not because I didn't understand them — I did — but because in the heat of building something, I second-guessed myself every time. Eventually I sat down and mapped out the decision framework I kept arriving at. This article is that map.

The short answer is: Flexbox for components, Grid for layouts. But that's oversimplified. The real answer lives in a single question: are you arranging items along one axis, or controlling them across two?

"The mistake isn't choosing the wrong one — it's forcing one to do the job of the other."

The Core Difference: 1D vs 2D

This is the one thing worth memorising. Flexbox works in one dimension at a time — either a row or a column. Grid works in two dimensions simultaneously — rows and columns at the same time.

display: flex1D
Items flow along one axis. Content controls size.
display: grid2D
Cells exist even without content. Layout controls size.

The visual difference matters: with Grid, the container defines the structure. Cells exist in the grid whether or not they have content. With Flex, the items define the structure — the container just manages their flow.

When to Use Flexbox

Flexbox excels when you need items to flow in a line and you want them to be flexible about how they fill that space. Use it for:

CSS Typical Flexbox nav
/* Navigation bar */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* Items inside can grow/shrink naturally */
.nav-links {
  display: flex;
  gap: 2rem;
  list-style: none;
}

When to Use CSS Grid

Grid is the right tool when the layout needs to exist independently of the content. You're defining columns and rows as a structure, then placing things into it.

Layout Pattern Flexbox Grid
Page-level layout (sidebar + main)✗ Awkward✓ Perfect
Card grids (equal column widths)✗ Needs hacks✓ Native
Nav bar (logo + links + cta)✓ Ideal✗ Overkill
Items that span multiple rows/columns✗ Not possible✓ grid-column/row
Centering a single element✓ Simpler✓ Also works
List of buttons/tags that wrap✓ flex-wrap✗ Wrong tool
Holy Grail layout (header/sidebar/main/footer)✗ Complex✓ Elegant
CSS Typical Grid page layout
/* Page shell with sidebar */
.page-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 3rem;
}

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

The Decision Framework

Ask these questions in order:

🤔
Do I need to control both rows AND columns?

If yes → Grid immediately. Don't debate it.

🤔
Am I laying out a page section or an entire page structure?

Page-level structure → Grid. Think header, main, sidebar, footer as named areas.

🤔
Are items flowing in a single line (or wrapping rows of equal-height items)?

Single-axis flow → Flexbox. Nav bars, button rows, tag lists, inline icon+label components.

🤔
Do I need items to span across multiple tracks?

Spanning rows or columns → Grid. A featured card spanning 2 columns, a sidebar spanning the full page height.

🤔
Is the layout about the content size, or about the space available?

Content-driven (items determine size) → Flexbox. Space-driven (columns/rows pre-defined) → Grid.

💡
Still unsure?

Use Both. Grid for the outer shell, Flexbox inside each card. They compose perfectly — there's no rule against nesting them.

How This Portfolio Uses Both

This very site is a good example of composition. The page-level structure (header, hero, sections, footer) uses Grid in places where multiple columns need to align. The nav bar is Flexbox. The project cards grid is Grid with auto-fit. Inside each project card, the badge + title + description stack is Flexbox. Inside each section's tag + title group, it's Flexbox.

Choosing between them is never an either-or. It's about matching the tool to the problem at the specific level of the component hierarchy you're working on. Page → Grid. Component → Flexbox. Content inside that component → probably Flexbox again.

Veeny Ree Mae Bautista

Veeny Ree Mae Bautista

UI/UX Designer & Frontend Web Developer

Based in Bataan, Philippines. BSIT graduate of Bataan Peninsula State University. I design and build thoughtful digital experiences — and occasionally write about the lessons that come with growing up in tech.