What You'll Learn
You'll learn how to combine flex-direction and flex-wrap into a single line of CSS using the flex-flow shorthand property.
The Shorthand Advantage
You've already learned that flex-direction controls whether your flex items flow horizontally or vertically, and flex-wrap controls whether items can break onto new lines. Writing both properties separately works perfectly fine, but CSS gives you a convenient shorthand: flex-flow.
Think of it like ordering a combo meal instead of ordering each item separately—you get the same result, just with less typing.
How flex-flow Works
The flex-flow property accepts two values in order:
- First value: the flex-direction (
row,column,row-reverse, orcolumn-reverse) - Second value: the flex-wrap behavior (
nowrap,wrap, orwrap-reverse)
Here's the syntax pattern:
flex-flow: <flex-direction> <flex-wrap>;
Common Examples
Instead of writing:
.container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
You can write:
.container {
display: flex;
flex-flow: row wrap;
}
Other valid combinations:
flex-flow: column nowrap;
flex-flow: row-reverse wrap;
flex-flow: column wrap-reverse;
You can also omit one value if you want to keep its default (row for direction, nowrap for wrap):
flex-flow: column; /* same as column nowrap */
Why Use It?
Using flex-flow keeps your CSS cleaner and more concise, especially when you need to set both properties together. It's purely a convenience feature—it doesn't add new functionality, just saves you a line of code.
Key Takeaway: flex-flow is a shorthand that combines flex-direction and flex-wrap into one property, written as flex-flow: <direction> <wrap>;.