Course contentsShow
← Web Development
Lesson 281 of 2,9825. FlexboxFree lesson

flex-shrink: Handling Space Constraints

Define how flex items shrink when the container is too small to fit them.

flex-shrink: Handling Space Constraints

What you'll learn: How to control whether and how much flex items shrink when there isn't enough space to fit them at their natural size.

When flex items are too large to fit comfortably in their container, something has to give. The flex-shrink property determines how willing each flex item is to shrink down to make room for others.

How Flex Shrink Works

By default, every flex item has flex-shrink: 1, which means they're all equally willing to shrink. If your container becomes too narrow, all items will shrink proportionally to fit.

Think of it like a group of friends squeezing into a car. If everyone has the same flex-shrink value, they all squeeze together equally. But if one person has flex-shrink: 0, they refuse to budge—everyone else has to squeeze even more.

Common Values

  • flex-shrink: 1 (default): Item will shrink proportionally with others
  • flex-shrink: 0: Item refuses to shrink below its natural size
  • flex-shrink: 2: Item will shrink twice as much as items with flex-shrink: 1

The actual shrinking calculation considers both the flex-shrink value and the item's size, so larger items contribute more to the shrinking even with the same shrink factor.

Practical Use

You might set flex-shrink: 0 on a logo or icon that should maintain its size, while letting text content shrink as needed. Or use higher shrink values on less critical content to protect more important elements.

Key Takeaway: flex-shrink controls how flex items compress when space is tight—set it to 0 to prevent shrinking, or use higher values to make items shrink more readily than others.