iTranslated by AI
Difference between flex-grow and flex-shrink

Hello everyone 🐒
I'm Osaru, who's been actively using Flexbox layouts.
The other day, a friend asked me about the difference between the CSS properties flex-grow and flex-shrink, so I thought I'd write an article about it... lol
⚖️ Overview of Each
flex-grow specifies the proportion of expansion, and flex-shrink specifies the proportion of shrinkage—they differ in what they control.
| Property | When there is extra space | When child elements are too large for the parent |
|---|---|---|
flex-grow |
Determines the proportion of expansion | No effect |
flex-shrink |
No effect | Determines the proportion of shrinkage |
✅ Practical Usage
| Use Case | Property to Define |
|---|---|
| Want to distribute extra space equally | Define flex-grow (e.g., 1) |
| Don't want to distribute extra space but want to shrink if overflowing | Define flex-shrink (e.g., 1) |
| Want a fixed size that doesn't change | Set both to 0(You can use the shorthand like flex: 0 0 auto;) |
👀 Sample
Although I've explained it, I think it might be hard to understand from text alone, so I've prepared a sample on CodePen!
flex-grow example
The parent element (.grow-container) uses width: 100%, while each child element (.box) has an appropriate flex-grow defined.
Expansion amount = Available space × (element's grow value ÷ total grow value)
It expands based on this calculation. The larger the flex-grow value compared to other elements, the more it expands!
flex-shrink example
The parent element (.grow-container) uses width: 100%, while each child element (.box) has an appropriate flex-shrink defined.
Shrink amount = Overflow amount × ((shrink value × base width) ÷ total (shrink value × base width))
It shrinks based on this calculation. The larger the flex-shrink value compared to other elements, the more it shrinks!
📚 Summary
-
flex-growdetermines how much to expand when there is extra space -
flex-shrinkdetermines how much to shrink when space is insufficient
To get the most out of Flexbox, it's key to properly use these two properties! 💡
Understanding the relationship and calculation rules of flex-grow and flex-shrink introduced here will help you create stable, intended layouts!
Well then, have a more comfortable Flex life~ 🐒✨
Discussion