flex-wrap: wrap-reverse for Bottom-Up Layouts
You'll learn how flex-wrap: wrap-reverse flips the cross-axis direction to stack wrapped lines from bottom to top.
What It Does
You already know that flex-wrap: wrap allows flex items to break into multiple lines when they can't fit in a single line. By default, those new lines stack downward (or rightward in columns)—the first line appears at the top, the second below it, and so on.
flex-wrap: wrap-reverse changes this behavior by reversing the cross-axis direction. New lines now stack from the bottom up instead of top down.
The Cross-Axis Reversal
Think of it like stacking plates:
- With
wrap, you place the first plate on the table, then stack additional plates above it. - With
wrap-reverse, you start at the ceiling and work your way down—the first line appears at the bottom, and additional lines appear above it.
This doesn't change the main axis (items still flow left-to-right or right-to-left based on flex-direction). It only affects where wrapped lines appear along the cross axis.
When You'd Use It
This property is useful when you want content to naturally "grow upward"—like chat messages in some messaging apps, or toolbar items that should appear from the bottom of a container first.
.container {
display: flex;
flex-wrap: wrap-reverse;
/* Items wrap, but new lines appear ABOVE previous ones */
}
Key Takeaway: flex-wrap: wrap-reverse reverses the cross-axis direction, making wrapped flex lines stack from bottom to top instead of top to bottom—perfect for layouts that need to grow upward.