The flex Shorthand Property
You'll learn how to combine three flex properties into a single, cleaner declaration.
You've already learned about flex-grow, flex-shrink, and flex-basis—the three properties that control how flex items size themselves. Writing all three separately works, but CSS gives you a more efficient way: the flex shorthand property.
How It Works
The flex property combines all three sizing behaviors into one line:
.item {
flex: <flex-grow> <flex-shrink> <flex-basis>;
}
For example, instead of writing:
.item {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 200px;
}
You can write:
.item {
flex: 1 1 200px;
}
Common Patterns
The order matters: grow, shrink, basis. Here are typical values you'll use:
/* Flexible item that grows and shrinks equally */
.flexible {
flex: 1 1 0;
}
/* Item that only grows, never shrinks */
.grow-only {
flex: 1 0 auto;
}
/* Fixed-size item that doesn't grow or shrink */
.fixed {
flex: 0 0 200px;
}
You can even use shorter versions like flex: 1 (equivalent to 1 1 0) or flex: auto (equivalent to 1 1 auto).
Why Use the Shorthand?
Think of it like ordering a combo meal instead of three separate items—you get everything you need in one go, with less typing and cleaner code. It also sets smart defaults when you omit values.
Key Takeaway: The flex shorthand combines flex-grow, flex-shrink, and flex-basis in that order, making your flexbox code more concise and maintainable.