Skip to main content
CSS Tip

The unknown behavior of flex-wrap

flex-wrap: wrap allows items to wrap onto multiple lines but it has another function. It transforms your flex container from a single-line to a multi-line container even if at the end you have only one flex line. This means we can use align-content to align the content.

In other words, you need to use flex-wrap: wrap to align the content using align-content even if there is no wrapping.

flex-wrap & align-content

It's different from align-items which aligns the items inside the line whereas align-content aligns the whole line. Here is an interactive demo to see the behavior of each property:

See the Pen flex-wrap & alignment by Temani Afif (@t_afif) on CodePen.


More CSS Tips