Multi-Line Alignment with align-content
What you'll learn: How to distribute space between multiple lines of flex items when they wrap onto new rows or columns.
The Core Idea
When you use flex-wrap: wrap or flex-wrap: wrap-reverse, your flex items can break across multiple lines. The align-content property controls how those lines themselves are spaced along the cross axis.
Think of it like organizing shelves in a bookcase. align-items arranges books on each individual shelf, but align-content decides how the shelves themselves are distributed within the entire bookcase—should they be packed at the top, spread evenly, or centered?
Important: align-content only works when items wrap across multiple lines. If everything fits on one line, this property has no effect.
How align-content Works
This property accepts several values:
flex-start— Lines pack at the start of the cross axisflex-end— Lines pack at the endcenter— Lines center in the containerspace-between— First line at start, last at end, equal space betweenspace-around— Equal space around each linespace-evenly— Equal space between all lines and edgesstretch(default) — Lines stretch to fill available space
The Key Difference
Remember: align-items aligns individual items within their line, while align-content aligns the lines themselves within the container. You need both multiple lines (wrapping) and extra space on the cross axis for align-content to show its effect.
Key Takeaway: align-content distributes space between wrapped flex lines along the cross axis, controlling how multiple rows or columns are positioned within the flex container.