flex-shrink
Example
.avatar {
width: 40px;
}.avatar {
width: 40px;
flex-shrink: 0;
}flex-shrink: 0 keeps the avatar at 40px when the row runs out of space.
Common mistakes
- An icon gets squished next to long text.
flex-shrinkdoes nothing because the item'smin-width: autokeeps it at content size.
Key points
- Fixed-size items like icons and avatars set
flex-shrink: 0. - Text items that should shrink also set
min-width: 0so long content can be truncated.
Interview questions
What is the default flex-shrink value?
It is 1, so every flex item can shrink when the container is too small.
Why won't my flex item shrink below its content?
Flex items have min-width: auto by default. Set min-width: 0 or overflow: hidden to let them shrink further.