When laying out a component, how do you decide between CSS Flexbox and Grid, and where do you combine them?

technical-conceptual · Mid level · software-engineering

What the interviewer is really asking

Assesses whether the candidate understands the one-dimensional vs two-dimensional model behind Flexbox and Grid and can choose pragmatically, rather than memorizing one tool for everything.

What to say

What to avoid

Example answers

Strong: I ask whether I'm controlling one axis or two. A nav bar or a wrapping tag list is one-dimensional and content-driven, so Flexbox with flex-wrap and gap. A card dashboard with aligned rows and columns is two-dimensional, so Grid with grid-template-columns. In practice I use Grid for the page skeleton and make each cell a flex container to align its own content, and I lean on gap instead of margins since it's well supported now.

Weak: I mostly just use Flexbox for everything since I know it well. If something needs columns I nest a bunch of flex containers until it looks right. Grid feels complicated so I avoid it.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.