CSS flex-grow Property
The flex-grow property determines how much a flex item can grow relative to other flex items when positive free space is available in a flex container.
It accepts a non-negative number called a growth factor. Items with larger growth factors receive a greater share of the available space, subject to their base sizes and sizing constraints. The property applies to flex items, not the flex container itself.
flex-grow Syntax
The flex-grow property accepts a single non-negative number. The number represents the item's growth factor relative to other flexible items on the same flex line.
Basic Syntax
selector {
flex-grow: 1;
}
Common Values
.item-one {
flex-grow: 0;
}
.item-two {
flex-grow: 1;
}
.item-three {
flex-grow: 2;
}
.item-four {
flex-grow: 0.5;
}
CSS-Wide Keywords
.item {
flex-grow: inherit;
}
.item {
flex-grow: initial;
}
.item {
flex-grow: unset;
}
.item {
flex-grow: revert;
}
.item {
flex-grow: revert-layer;
}
The initial value is 0, which means a flex item does not grow to consume positive free space unless a growth factor is specified.
Negative values, percentages, and length units such as px are not valid for flex-grow.
Property Values
The value of flex-grow is a non-negative number. Whole numbers and decimals are allowed.
| Value | Description |
|---|---|
0 |
Prevents the item from growing to consume positive free space. This is the initial value. |
1 |
Allows the item to receive a proportional share of positive free space. |
2 |
Assigns twice the growth factor of an item using 1. |
0.5 |
Assigns half the growth factor of an item using 1. |
<number> |
Any finite, non-negative number representing the growth factor. |
CSS-Wide Values
| Value | Description |
|---|---|
inherit |
Uses the computed flex-grow value of the parent element. |
initial |
Restores the initial value, 0. |
unset |
Restores 0 because the property is not inherited. |
revert |
Reverts the property according to the CSS cascade origins. |
revert-layer |
Reverts the property according to the CSS cascade layers. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | 0 |
| Inherited | No |
| Applies to | Flex items |
| Computed value | As specified |
| Animation type | Number |
| Percentages | Not applicable |
Unlike the discrete values of flex-direction, numeric flex-grow values can interpolate during CSS animations and transitions.
How It Works
Flexbox first determines the base sizes of the flex items. When positive free space remains along the main axis, eligible items can grow according to their flex-grow factors.
Step 1: Create a Flex Container
.container {
display: flex;
width: 600px;
}
Step 2: Define Item Bases
.item {
flex-basis: 100px;
}
Each item begins with a flex basis of 100px, subject to sizing constraints.
Step 3: Allow Items to Grow
.item {
flex-grow: 1;
}
Items with equal growth factors receive equal shares of the positive free space when their sizing constraints do not interfere.
Step 4: Assign Different Growth Factors
.item-one {
flex-grow: 1;
}
.item-two {
flex-grow: 2;
}
.item-three {
flex-grow: 1;
}
The growth factors form a ratio of 1:2:1. The second item receives twice the additional space assigned to either of the other items, assuming equal bases and no limiting constraints.
Important Distinction
flex-grow distributes additional space. It does not directly assign a percentage of the container's total width or height.
Growth Factors
A growth factor expresses how much an item participates in distributing positive free space relative to other items on the same flex line.
Equal Growth Factors
.item-one {
flex-grow: 1;
}
.item-two {
flex-grow: 1;
}
.item-three {
flex-grow: 1;
}
All three items receive equal shares of the available positive free space, assuming no sizing constraints change the distribution.
Unequal Growth Factors
.item-one {
flex-grow: 1;
}
.item-two {
flex-grow: 3;
}
.item-three {
flex-grow: 1;
}
The ratio is 1:3:1. The middle item receives three times the additional space assigned to either outer item.
Decimal Growth Factors
.item-one {
flex-grow: 0.5;
}
.item-two {
flex-grow: 1;
}
.item-three {
flex-grow: 0.5;
}
Decimal values are valid. In this example, the factors total 2, so all positive free space can be distributed proportionally when sizing constraints permit.
Growth Factors Below One
.item-one {
flex-grow: 0.2;
}
.item-two {
flex-grow: 0.3;
}
The growth factors total 0.5. When the total growth factor is below 1, Flexbox may leave some positive free space undistributed rather than scaling the factors to consume all of it.
Important Consideration
Growth factors are relative weights, not fixed dimensions. The final size also depends on flex bases, available space, gaps, and minimum or maximum size constraints.
Distributing Free Space
Positive free space is the space remaining along the main axis after accounting for the flex items' base sizes and other relevant layout requirements.
Example Calculation
Consider a container that is 600px wide with three items, each having a flex basis of 100px. Assume there are no gaps, margins, borders, padding, or limiting size constraints.
| Measurement | Value |
|---|---|
| Container width | 600px |
| Combined flex bases | 300px |
| Positive free space | 300px |
| Growth factors | 1:2:1 |
| Total growth factor | 4 |
Calculate the Additional Space
Each item's share is calculated using its growth factor divided by the total growth factor.
Item 1: 300px × (1 / 4) = 75px
Item 2: 300px × (2 / 4) = 150px
Item 3: 300px × (1 / 4) = 75px
Final Item Sizes
| Item | Base Size | Growth | Final Size |
|---|---|---|---|
| Item 1 | 100px | 75px | 175px |
| Item 2 | 100px | 150px | 250px |
| Item 3 | 100px | 75px | 175px |
CSS Example
.container {
display: flex;
width: 600px;
}
.item {
flex-basis: 100px;
min-width: 0;
}
.item-one {
flex-grow: 1;
}
.item-two {
flex-grow: 2;
}
.item-three {
flex-grow: 1;
}
This calculation illustrates the basic distribution model. Actual Flexbox sizing can require additional adjustments when minimum sizes, maximum sizes, or other constraints apply.
flex-grow: 0
The value 0 prevents a flex item from receiving additional positive free space through the flex growth algorithm.
Syntax
.item {
flex-grow: 0;
}
Example
.container {
display: flex;
gap: 15px;
}
.sidebar {
flex-grow: 0;
flex-basis: 200px;
}
.content {
flex-grow: 1;
flex-basis: 200px;
}
How It Works
The sidebar does not grow to consume extra space. The content area can expand into the remaining positive free space.
Important Consideration
flex-grow: 0 does not prevent shrinking. The item may still shrink if its flex-shrink value allows it and the container lacks sufficient space.
flex-grow: 1
The value 1 allows a flex item to participate in distributing positive free space.
Syntax
.item {
flex-grow: 1;
}
Example
.container {
display: flex;
gap: 10px;
}
.item {
flex-grow: 1;
flex-basis: 0;
min-width: 0;
}
How It Works
All items have the same growth factor and a zero flex basis, so they can occupy equal main-axis sizes when minimum and maximum constraints do not interfere.
Why flex-basis Matters
.item {
flex-grow: 1;
flex-basis: auto;
}
With flex-basis: auto, items can begin with different base sizes. Equal growth factors then distribute equal amounts of additional space, but the final item sizes may remain unequal.
Important Consideration
Setting flex-grow: 1 alone does not guarantee equal-width or equal-height items. Their base sizes and minimum size constraints also matter.
Unequal Growth
Different growth factors allow selected flex items to receive larger or smaller shares of positive free space.
Example
.container {
display: flex;
gap: 10px;
}
.item-one {
flex: 1 1 0;
}
.item-two {
flex: 2 1 0;
}
.item-three {
flex: 1 1 0;
}
With zero flex bases and no limiting size constraints, the items occupy main-axis space in a 1:2:1 ratio.
Using a Larger Growth Factor
.primary {
flex-grow: 3;
}
.secondary {
flex-grow: 1;
}
The primary item receives three times the additional space assigned to the secondary item when both participate in the same growth calculation.
Growth Is Not a Width Ratio
If the items have different flex bases, a 3:1 growth ratio does not necessarily produce final widths in a 3:1 ratio.
Important Consideration
Use a consistent flex basis when the goal is proportional final sizing rather than simply proportional distribution of additional space.
Relationship with flex-basis
The flex-basis property determines an item's initial main size before flexible growth and shrinking are applied.
Using auto
.item {
flex-grow: 1;
flex-basis: auto;
}
With auto, the base size can depend on the item's main-size property or its content. Items with different bases may remain different sizes after receiving equal shares of extra space.
Using Zero
.item {
flex-grow: 1;
flex-basis: 0;
min-width: 0;
}
A zero flex basis allows items to begin from the same main-axis base size. With equal growth factors, this can produce equal sizes when constraints permit.
Using a Fixed Basis
.item {
flex-grow: 1;
flex-basis: 180px;
}
Each item starts with a flex basis of 180px and can grow when positive free space is available.
Comparison
| Property | Purpose |
|---|---|
flex-basis |
Establishes the initial main size before flexible sizing. |
flex-grow |
Controls the distribution of positive free space. |
Important Consideration
For a row layout in a horizontal writing mode, the main size is typically width. For a column layout, it is typically height.
Relationship with flex-shrink
The flex-grow and flex-shrink properties control different situations in the Flexbox sizing algorithm.
Positive Free Space
.item {
flex-grow: 1;
}
When positive free space is available, eligible items can grow according to their growth factors.
Negative Free Space
.item {
flex-shrink: 1;
}
When items require more main-axis space than the container provides, eligible items can shrink according to their scaled shrink factors and sizing constraints.
Comparison
| Characteristic | flex-grow | flex-shrink |
|---|---|---|
| Initial value | 0 |
1 |
| Space condition | Positive free space | Negative free space |
| Purpose | Controls growth | Controls shrinking |
| Accepted values | Non-negative numbers | Non-negative numbers |
Using Both Properties
.item {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 200px;
}
The item can grow when extra space exists and shrink when space is insufficient, subject to its minimum and maximum size constraints.
flex Shorthand
The flex shorthand combines flex-grow, flex-shrink, and flex-basis.
Individual Properties
.item {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 200px;
}
Equivalent Shorthand
.item {
flex: 1 1 200px;
}
Common Shorthand Values
| Declaration | Meaning |
|---|---|
flex: initial |
Equivalent to 0 1 auto. |
flex: auto |
Equivalent to 1 1 auto. |
flex: none |
Equivalent to 0 0 auto. |
flex: 1 |
Commonly expands to 1 1 0% in browsers. |
flex: 2 1 150px |
Sets growth to 2, shrinking to 1, and basis to 150px. |
Why the Shorthand Is Useful
The shorthand defines all three sizing components together and avoids accidentally retaining an earlier value for one of them.
Important Consideration
The flex shorthand applies to flex items. It is different from flex-flow, which controls direction and wrapping on the flex container.
Row and Column Layouts
The flex-grow property distributes space along the main axis, which is determined by flex-direction.
Row Layout
.container {
display: flex;
flex-direction: row;
width: 600px;
}
.item {
flex: 1 1 100px;
}
In a horizontal writing mode, the items grow horizontally to occupy available main-axis space.
Column Layout
.container {
display: flex;
flex-direction: column;
height: 400px;
}
.item {
flex: 1 1 80px;
}
In a horizontal writing mode, the items grow vertically when the container has positive free space along its height.
Main-Axis Comparison
| Direction | Growth Axis |
|---|---|
row |
Inline axis |
row-reverse |
Inline axis, reversed |
column |
Block axis |
column-reverse |
Block axis, reversed |
Important Consideration
A column flex container generally needs a definite or otherwise constrained main-axis size for visible vertical growth. If the container expands to fit its contents, there may be no positive free space to distribute.
Minimum and Maximum Sizes
Minimum and maximum size constraints can limit the effect of flex-grow.
Maximum Width
.item {
flex-grow: 1;
max-width: 300px;
}
In a horizontal row layout, the item cannot grow beyond its maximum width. Remaining free space may be redistributed among other eligible items.
Minimum Width
.item {
flex-grow: 1;
min-width: 150px;
}
The item cannot become narrower than 150px, even if the available space is limited.
Automatic Minimum Size
Flex items often have an automatic minimum size based on their content. Long words, large images, or other unbreakable content can prevent an item from becoming as small as expected.
Allowing a Row Item to Shrink
.content {
flex: 1 1 0;
min-width: 0;
overflow-wrap: anywhere;
}
Setting min-width: 0 removes the automatic minimum width constraint for this row item. The wrapping rule helps long text fit within the reduced space.
Allowing a Column Item to Shrink
.content {
flex: 1 1 0;
min-height: 0;
overflow: auto;
}
For a column layout, min-height: 0 can allow the item to shrink below its content-based minimum height. The overflow rule provides scrolling when necessary.
Important Consideration
Growth factors do not override minimum or maximum size constraints. The flex sizing algorithm accounts for those constraints when determining final sizes.
Responsive Layouts
The flex-grow property helps build layouts that expand naturally into available space without requiring fixed widths for every item.
Flexible Content with Fixed Sidebar
.layout {
display: flex;
gap: 20px;
}
.sidebar {
flex: 0 0 220px;
}
.main-content {
flex: 1 1 0;
min-width: 0;
}
The sidebar maintains its assigned width, while the main content grows to fill the remaining horizontal space.
Responsive Card Layout
.cards {
display: flex;
flex-wrap: wrap;
gap: 15px;
}
.card {
flex: 1 1 220px;
min-width: 0;
}
Cards grow within each flex line and wrap when there is insufficient room for another card.
Responsive Layout Change
@media (max-width: 700px) {
.layout {
flex-direction: column;
}
.sidebar {
flex: 0 1 auto;
}
.main-content {
flex: 1 1 auto;
}
}
On narrower screens, the sidebar and main content stack vertically, and their flex sizing values are adjusted for the new main axis.
Important Consideration
In a wrapping layout, growth is calculated separately for each flex line. A row containing fewer cards may produce wider cards than another row.
flex-grow Example
This example compares equal growth factors, unequal growth factors, and a layout where only one item grows. Each container uses the same three numbered items.
HTML Example
<div class="grow-demo">
<h3>Equal Growth: 1, 1, 1</h3>
<div class="grow-equal">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<h3>Unequal Growth: 1, 2, 1</h3>
<div class="grow-unequal">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<h3>Only Middle Item Grows: 0, 1, 0</h3>
<div class="grow-middle">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</div>
CSS Example
.grow-demo > div {
display: flex;
gap: 8px;
margin-bottom: 20px;
padding: 10px;
background-color: #f1f5f9;
}
.grow-demo > div > div {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
flex-basis: 0;
flex-shrink: 1;
min-width: 0;
min-height: 45px;
background-color: #336699;
color: #fff;
font-weight: bold;
}
.grow-demo .grow-equal > div {
flex-grow: 1;
}
.grow-demo .grow-unequal > div {
flex-grow: 1;
}
.grow-demo .grow-unequal > div:nth-child(2) {
flex-grow: 2;
}
.grow-demo .grow-middle > div {
flex-grow: 0;
flex-basis: 50px;
}
.grow-demo .grow-middle > div:nth-child(2) {
flex-grow: 1;
}
Equal Growth: 1, 1, 1
Unequal Growth: 1, 2, 1
Only Middle Item Grows: 0, 1, 0
In the first example, all three items grow equally. In the second, the middle item receives twice the additional space of either outer item. In the third, only the middle item grows, while the outer items retain their 50px flex bases.
The examples demonstrate how growth factors distribute positive free space without changing the HTML source order.
Common Mistakes
Several common misunderstandings can make flex-grow appear to behave unexpectedly.
Expecting flex-grow to Set a Percentage
.item {
flex-grow: 2;
}
This does not mean the item becomes twice as wide as every other item. It receives a proportional share of additional space.
Expecting Growth Without Free Space
If the flex items already occupy all available main-axis space, there may be no positive free space for flex-grow to distribute.
Applying flex-grow to the Container
.container {
display: flex;
}
.container > div {
flex-grow: 1;
}
The growth factor belongs on the flex items. Setting it on a container does not control the growth of that container's children.
Ignoring flex-basis
Equal growth factors do not necessarily create equal final sizes when the items begin with different flex bases.
Ignoring Minimum Sizes
Content-based minimum sizes can prevent flex items from shrinking as expected. Review min-width or min-height when content overflows.
Confusing Growth and Shrinking
flex-grow controls positive free space. flex-shrink controls how items respond to negative free space.
Assuming All Wrapped Lines Share Space
Each flex line distributes its own free space. Items on different lines do not participate in one shared growth calculation.
Important Considerations
Keep the following points in mind when using flex-grow:
- Purpose: Controls how flex items receive positive free space.
- Initial value:
0. - Inheritance: The property is not inherited.
- Applies to: Flex items.
- Accepted values: Non-negative numbers, including decimals.
- Invalid values: Negative numbers, percentages, and length units.
- Growth factor: Determines an item's relative share of positive free space.
- Zero: Prevents growth but does not necessarily prevent shrinking.
- One: Allows proportional participation in growth.
- Larger values: Assign greater relative growth factors.
- Decimal values: Are valid and can be useful for proportional growth.
- Factors below one: A total below
1can leave some positive free space unused. - Free space: Must be available for growth to occur.
- flex-basis: Establishes the initial main size before flexible sizing.
- flex-shrink: Controls shrinking when space is insufficient.
- flex shorthand: Combines growth, shrinking, and basis.
- Main axis: Growth follows the direction established by
flex-direction. - Row layouts: Growth usually affects width in a horizontal writing mode.
- Column layouts: Growth usually affects height in a horizontal writing mode.
- Minimum sizes: Can restrict how small items become.
- Maximum sizes: Can limit growth.
- Wrapping: Growth is calculated independently for each flex line.
- Equal factors: Do not guarantee equal final sizes when bases differ.
- Animation: Numeric growth factors can interpolate.
- Responsive layouts: Growth factors help items adapt to changing container sizes.
Use flex-grow when flex items need to expand into available space. For predictable results, consider the item's flex basis, shrink factor, minimum and maximum sizes, and the amount of free space in the container.
Browser Support
The CSS flex-grow property is Widely available and supported by modern browsers, including Chrome, Edge, Firefox, and Safari.
Standard, unprefixed Flexbox growth behavior has broad support. Older browsers may have used prefixed or earlier Flexbox implementations.
Supported Example
.container {
display: flex;
}
.container > div {
flex-grow: 1;
}
Feature Detection
@supports (display: flex) and (flex-grow: 1) {
.container {
display: flex;
}
.container > div {
flex-grow: 1;
}
}
Fallback Example
.container > div {
display: block;
}
@supports (display: flex) and (flex-grow: 1) {
.container {
display: flex;
}
.container > div {
flex-grow: 1;
}
}
Without Flexbox support, the items remain in normal block layout. Supporting browsers can distribute available space among the flex items.
Compatibility Considerations
Although support is broad, test layouts involving intrinsic content sizes, minimum dimensions, and nested flex containers when precise sizing behavior is important.
For current compatibility information, visit Can I Use? .
Specifications
The flex-grow property is defined in the CSS Flexible Box Layout Module Level 1. The specification describes how growth factors participate in distributing positive free space among flex items.
CSS Flexible Box Layout Module Level 1: flex-grow Property
The flexible length resolution algorithm defines how available space is distributed and how minimum and maximum size constraints are handled.
CSS Flexible Box Layout Module Level 1: Resolving Flexible Lengths
These rules establish the relationship between flex bases, growth factors, free space, and the final main sizes of flex items.
