liveBook · Manning

Flex-grow

As explained in Web Design Playground

A flexbox sizing behavior that allows a flex item to take up available free space.

flex-grow is a flexbox property for sharing leftover room. Think of a flex container as a row or column with a little spare space after its items have been placed. By default, every flex item has flex-grow: 0, so that spare space stays empty. Give an item a positive value and it expands into the available space. section 12.6

item {
    flex-grow: value;
}

Apply flex-grow to the flex item you want to expand. Replace value with a positive number when the item should claim some empty space. section 12.6

The numbers act like shares of the empty space:

  • One growing item gets all available empty space, whatever positive number it uses. section 12.6
  • Items with equal positive values split available empty space evenly. section 12.6
  • Items with different values split space in proportion to those values. Values of 1, 2, and 1 give 25%, 50%, and 25% of the empty space. section 12.6

A roomy article and a smaller sidebar

In a two-item layout, article { flex-grow: 3; } and aside { flex-grow: 1; } divide available horizontal space into four shares. The article receives three shares, or 75%, while the sidebar receives one share, or 25%. The values describe the spare space allocation, not a fixed width recipe. section 12.17 section 12.6

flex-grow can also solve the classic “footer should sit at the bottom” layout. Make the page body a vertical flex container, give it min-height: 100vh, and set main to flex-grow: 1. The main area uses empty vertical space, leaving the footer at the bottom when page content is short. section 12.17

For flexible groups of blocks, flex-grow works alongside flex-wrap, flex-basis, and flex-shrink. Growing items can preserve desired proportions; wrapping handles narrow viewports; a basis and disabled shrinking can establish a minimum block size. That combination is useful when replacing fragile faux-column layouts. section 13.9 section 12.18

Try a quick share test

Create three flex items and try flex-grow values of 1, 1, and 1. Then change the middle value to 2. Watch the middle item take half of the available empty space while the outer items take one quarter each. Next, try the same idea in a thumbnail list, where an image sits beside descriptive text. section 12.6 section 12.8

How Web Design Playground covers it

How deep it goes
Explains defaults, positive values, equal shares, and proportional calculations, without detailing browser sizing internals.
Examples
Uses article-and-sidebar proportions, a full-height footer layout, flexible blocks, and thumbnail lists.
What it assumes
Introduces flex-grow through a flex-item question and property syntax without stated prior CSS requirements.
What you can do after
Apply it to allocate available space among flex items using equal or proportional positive values.
How it connects
Connects flex-grow with flex-wrap, flex-shrink, flex-basis, align-items, and flex-direction.

Also explained in

Compare how 4 books explain flex-grow →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground. The section links point to the parts of the book it draws on.