CSS Grid vs Flexbox: When to Use Which

Grid and Flexbox are not competitors — they're complementary tools for different jobs. Use them right and CSS layout becomes nearly effortless. Use them wrong and you fight the browser. This guide gives you the decision rules.

Side-by-Side

AspectFlexboxGrid
Dimensionality1D (row or column)2D (rows and columns)
Sizing modelContent-drivenContainer-driven
StrengthDistributing items along an axisAligning items across both axes
Typical useNav, button groups, card contentPage layout, card grids, dashboards
Gap supportYesYes (better tooling)
SubgridN/AYes

Decision Rules

  1. Is the layout one-directional? Flexbox.
  2. Do items need to align across rows and columns simultaneously? Grid.
  3. Do you want the container to dictate structure? Grid.
  4. Do you want content to dictate sizing? Flexbox.
  5. Are you building a page layout? Grid for the outer structure; Flexbox inside.

Common Patterns

Holy grail page layout (Grid):

.page {
  display: grid;
  grid-template:
    "header header" auto
    "sidebar main" 1fr
    "footer footer" auto / 240px 1fr;
}

Auto-flow card grid (Grid):

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

Nav bar (Flexbox):

.nav { display: flex; align-items: center; gap: 16px; }
.nav .spacer { flex: 1; }

Centering anything (Flexbox or Grid):

.center { display: grid; place-items: center; }

Try It Yourself

Generate box shadows, gradients, and other CSS effects with DesignKit's CSS tools.

Box Shadow Generator →

Frequently Asked Questions

Flexbox is 1D (one axis); Grid is 2D (rows and columns simultaneously).
Single-axis layouts: navs, button groups, card content, form fields, stacks.
Two-dimensional layouts: page structure, card grids, dashboards.
Yes — Grid for page-level, Flexbox for component-level. Standard pattern.
Lets nested grids inherit parent tracks — solves cross-card alignment. Broadly supported now.