CSS Reference ยท Flexbox
The flex-grow property
Reference for the CSS flex-grow property: how a flex item takes a share of the leftover space, how ratios work, why fractions behave differently, with examples.
The flex-grow property sets the growth factor of a flex item: how large a share of the container's leftover space it receives. After the browser lays out every item at its flex-basis, any space still free along the main axis is divided among the items in proportion to their growth factors.
With the default of 0 an item never grows beyond its basis.
CSS
.sidebar { flex-grow: 0; } .content { flex-grow: 1; } /* takes everything the sidebar leaves */
Try it
Syntax
CSS
flex-grow: <number>; flex-grow: 0; flex-grow: 2.5;
- Initial value:
0 - Applies to: flex items
- Inherited: no
- Animatable: yes, as a number
- Computed value: as specified
Values
| Value | Description |
|---|---|
0 |
The item does not grow. |
<number> |
A non-negative number. The item gets number รท sum of all growth factors of the free space. Negative values are invalid. |
Usage notes
- It shares free space, not total width. The final width is
flex-basisplus the item's share. Two items withflex-grow: 1but different bases end up with different widths. To get equal widths, set the basis to0too (that is whatflex: 1does). - Fractions below 1. If all the growth factors add up to less than 1, the items share only that fraction of the free space. The rest stays empty. Three items at
0.2use 60% of the leftover space. - There must be free space. If the items already fill the line, growing does nothing. In a column container without a set height there is no free space.
- Limits still apply.
max-width(ormax-height) caps an item, and the space it could not take is passed to the other growing items. - Margins can win. An
automargin on the main axis absorbs free space before growth happens, so the item will not grow. - Prefer
flex. Writingflex-grow: 1leaves the basis atauto, which is not the same asflex: 1.
Browser support
Supported in every browser.
Related
flex,flex-basis,flex-shrinkjustify-contentโ used when nothing grows- Lesson: Flex item properties