HomeBlogHTML & CSS
HTML & CSS

CSS Flexbox vs Grid: When to Use Which (And What Interviewers Ask)

Flexbox and Grid confuse most front-end beginners. Here's a clear breakdown of when to use each — and the questions you'll face in interviews.

Examifyr·Apr 2026·5 min read

"When would you use Flexbox vs Grid?" is one of the most common front-end interview questions. Most beginners either can't answer it clearly, or give a vague response that doesn't land.

Here's the clear answer — plus the properties and edge cases that show up on exams.

The one-line answer

Flexbox is for one dimension (a row OR a column). Grid is for two dimensions (rows AND columns at the same time).

That's the answer interviewers want to hear first. Everything else is detail.

When to use Flexbox

Flexbox works along a single axis. It's ideal for:

  • Navigation bars (items in a row)
  • Centering content (vertically and horizontally)
  • Distributing space between items in a line
  • Card components where items need to stretch to equal height
.nav {
  display: flex;
  justify-content: space-between;  /* horizontal spacing */
  align-items: center;             /* vertical centering */
}

Key properties to know: flex-direction, justify-content, align-items, flex-wrap, flex-grow.

When to use Grid

Grid controls both rows and columns simultaneously. It's ideal for:

  • Page layouts (header, sidebar, main content, footer)
  • Card grids where items must align in both directions
  • Complex layouts where items span multiple rows or columns
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;   /* sidebar + main */
  grid-template-rows: 64px 1fr 48px; /* header + content + footer */
  gap: 16px;
}

Key properties to know: grid-template-columns, grid-template-rows, gap, grid-column, grid-row, fr unit.

The exam questions that trip people up

Q: What does justify-content do in Flexbox vs Grid?

In both, it aligns items along the main axis. In Flexbox the main axis defaults to horizontal (row). In Grid it aligns the grid tracks within the container.

Q: What is the difference between align-items and align-content?

align-items aligns items within a single row/line. align-content aligns multiple rows/lines within the container. It only has an effect when items wrap.

Q: What does 1fr mean in Grid?

fr stands for "fraction of remaining space". grid-template-columns: 1fr 2fr means the second column gets twice the space of the first.

Can you use both at the same time?

Yes — and this is a good answer to give in interviews. Use Grid for the overall page layout, Flexbox for components within each grid area. They're complementary, not competing.

/* Grid for page layout */
.page { display: grid; grid-template-columns: 240px 1fr; }

/* Flexbox for nav inside the header */
.nav { display: flex; justify-content: space-between; }

See how you score under test conditions

CSS layout questions feel different when you're timed and can't look anything up. The Examifyr HTML & CSS quiz tests you on Flexbox, Grid, selectors, and responsive design — and shows you exactly which concepts you need to revisit.

🎯

Think you're ready? Prove it.

Take the free HTML & CSS readiness test. Get a score from 0–100, a topic breakdown, and your exact weak areas — in under 20 minutes.

Take the free HTML & CSS test →

Free · No sign-up · Instant results

More from Examifyr

← All articles