HomeGuideLabGlossary

Expand a flex item to fill unused space

The Solution at a Glance

Make flex items grow with a flex-grow greater than 0

By default, flex items don’t grow to fill any potential unused space inside the flex container’s content box. They ask to be a certain size based on their content. And if they get to be that size, they’re satisfied.

Flex items don’t grow by default because the initial value of flex-grow is 0. 0 means “no thank you, I don’t want to grow at all if given the chance”.

1There’s lots of unused space leftNo, thank you!Would you like to grow?flex-grow: 0INITIALPROPERTY VALUE

To make a flex item grow, set its flex-grow to any number greater than zero.

11There’s lots of unused space leftYes, please!Would you like to grow?flex-grow: 1

Different flex-grow values make flex items grow at different rates relative to each other

If you have multiple flex items that want to grow, you can have some of them of them grow more relative to others by giving them a higher value of flex-grow compared to the others.

For example, a flex item with flex-grow: 2 will grow by twice as many pixels as a flex item with flex-grow: 1.

1212flex-grow: 1flex-grow: 2

Make sure the flex container has unused space for flex items to grow into

Keep in mind there has to be unused space inside the flex container’s content box for the flex items to grow into.

12!

If a flex container’s size depends on the size of the flex items, there won’t be any unused space.

12No unused space leftinline-size: min-content

You’ll need to make sure the flex container is sized the way you want by following the rules of the type of layout used for the flex container. Just as the flex container lays out its child boxes using Flexbox, so the parent of the flex container can choose a different type of layout for the flex container.