20 / 21

What is the difference between align-content in Grid and in Flexbox?

Difficulty: 5/10
align-content, CSS Grid, Flexbox

Difference Between align-content in Grid and Flexbox

The align-content property in both Grid and Flexbox is used to align the entire content along the block (vertical) axis when there is extra space. However, its behavior differs slightly due to the way Grid and Flexbox handle layout.

Key Differences
  1. 1

    In Grid, align-content aligns the entire grid within the container when the total grid height is less than the container height.

  2. 2

    In Flexbox, align-content aligns the flex lines within the container when there are multiple lines (i.e., flex-wrap: wrap is used).

  3. 3

    If there is only one line of items in Flexbox, align-content has no effect; Grid always treats the grid as multiple tracks for alignment purposes.

  4. 4

    Both support values like start, end, center, stretch, space-between, space-around, and space-evenly.

Example: align-content in Grid vs Flexbox

Scenario Questions

0-2 years experience

  1. 1You have a flex container with three rows of items and you set align-content: space-between. What do you expect to see, and how would that change if you switched the container to a CSS Grid with the same property?
  2. 2In a simple page using Flexbox, extra vertical space isn’t being distributed among rows. Which property would you adjust, and why would the result differ if you used Grid instead?

2-5 years experience

  1. 1We added a new breakpoint to a dashboard that uses a flex column layout, and the rows stopped centering vertically. How would you check if align-content is the cause, and what would you change if we moved the layout to Grid?
  2. 2A component uses CSS Grid with align-content: stretch, but when placed inside a flex parent the inner items don’t fill the height as expected. Explain why this happens and how you’d fix it.

5-8 years experience

  1. 1Design a reusable UI component library that supports both Flexbox and Grid. How would you expose align-content options so developers get consistent behavior across the two systems, and what trade‑offs would you consider?
  2. 2For a large e‑commerce site we need a product‑listing that may wrap. Discuss how the differences in align-content between Grid and Flexbox affect layout stability and performance at scale, and which layout you’d choose.

8+ years experience

  1. 1Our legacy codebase heavily uses Flexbox with align-content for vertical centering, but we plan to migrate to CSS Grid for better two‑dimensional control. Outline a migration strategy that handles the differing align-content behavior, minimizes visual regressions, and aligns with cross‑team design tokens.
  2. 2A design system token for “content alignment” must work in both Grid and Flexbox contexts. How would you define the token semantics and implementation guidelines to accommodate the divergent behavior of align-content, and what governance would you put in place?

Follow-up Questions

  • When would align-content have no visual impact?
  • How does align-content interact with align-items?
  • What layout property would you use to align items within a single line?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.