Skip to main content

How does flex-wrap affect the alignment of elements?

When flex-wrap is enabled (wrap or wrap-reverse), the container may end up with multiple lines of flex items. In that case:

  • justify-content continues to align elements along the main axis within each line
  • align-items aligns elements within a single line along the cross axis
  • the align-content value comes into play: it controls the alignment of LINES relative to each other, when there are several of them

In short

PropertyWorks with wrapWhat it aligns
justify-contentyeselements in a line (along the main axis)
align-itemsyeselements within a line (along the cross axis)
align-contentonly if there are multiple linesthe lines themselves (along the cross axis)

Conclusion: flex-wrap itself does not align elements, but it enables multi-line mode, which is why align-content, responsible for distributing the lines, starts to matter.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

How does flex-wrap affect the alignment of elements?: CSS Interview Question