LATEST 🚀 Welcome to Upgradix by Shrash Studio – Your destination for free technology learning and career growth.
🕘 Updated:
HTML & CSS

Flex Grow – Controlling How Items Expand

flex-grow on a flex item to set how much of the container's leftover space (the free space) that item receives. The default is 0, which means the item never grows beyond its base size. The value is a unitless, non-negative number.

Flex Grow – Controlling How Items Expand

Quick Answer: Use flex-grow on a flex item to set how much of the container's leftover space (the free space) that item receives. The default is 0, which means the item never grows beyond its base size. The value is a unitless, non-negative number. Free space is shared in proportion to these numbers, so an item with 2 gets twice the share of an item with 1. The share is added to the item's base size, so flex-grow does not set the final width by itself. Writing flex: 1 is a shorthand for flex: 1 1 0%, which gives every item the same starting size.

S1. Why Do We Need Flex Grow?

Imagine the navigation bar from the earlier articles. It is now 600px wide and has three items: the logo, a search box and a login button. Each item is 100px wide.

Together they use 300px. The other 300px of the bar is empty space on the right. The design says the search box should stretch to fill that space, and it should keep filling it when the bar becomes 800px or 400px wide.

Would you calculate the width of the search box yourself and write width: 400px? That works for one screen size, but it breaks as soon as the bar changes.

CSS Flexbox solves this with a property on the item itself: flex-grow. Let's first see what happens when we do not use it.

S2. The Problem: Leftover Space Nobody Uses

Free space = the room left in the flex container, on the main axis, after every item has taken its base size.

Imagine the 600px wide bar with three items, each 100px wide and 40px tall. The HTML order is Logo, Search, Login. No item has flex-grow.

Example 1: A bar where no item can grow

Assumption: In the output diagrams, one character is about 20px wide and one row is about 20px tall. A, B and C stand for Logo, Search and Login.

<!-- HTML -->
<nav class="bar">
    <div class="bar-item">Logo</div>
    <div class="bar-item">Search</div>
    <div class="bar-item">Login</div>
</nav>

/* CSS */
.bar {
    display: flex;
    width: 600px;
}

.bar-item {
    width: 100px;
    height: 40px;
    background: #E2E8F0;
}

Expected output

|AAAAABBBBBCCCCC               |
|AAAAABBBBBCCCCC               |

Each item keeps its 100px width.
The bar is 600px wide, so 300px on the right stays empty.
Search, the item that should fill the bar, is no wider than the others.

The page renders, but it is not the bar we wanted. Items with a fixed size never use the free space.

What goes wrong?

  1. Wasted space: The 300px of free space is left empty, because no item was told to use it.
  2. Hard-coded widths: Developers write width: 400px on the search box, which only fits one container width.
  3. Calculated widths: A value such as calc(100% - 200px) hides the intent and must be edited when a sibling changes size.
  4. Margin hacks: An auto margin can push an item to the edge, but it does not make any item larger.
  5. Script sizing: Measuring the bar and setting widths in JavaScript adds code for something CSS can already do.

Now think about many toolbars, page layouts and card rows on one website. Calculating widths for every one of them becomes harder to maintain.

Remember: The container is not broken. It places every item at its base size and leaves the rest empty. The real problem is that nobody said which item should take the leftover space.

Animation 1: How fixed sizes leave free space unused

Three items, no growing

The red highlights show every item staying at its base size while space is left over.

🏷️LogoBase size: 100pxDoes not grow
🔍SearchBase size: 100pxDoes not grow
🔑LoginBase size: 100pxDoes not grow
 
.bar (600px wide) 300px of free space unused · nothing grows
No flex-grow on any item

The animation highlights the items that stay small while the bar has empty space.

S3. The Solution: Let One Item Take the Free Space with flex-grow

Flexbox gives us a simpler design.

flex-grow = a property on a flex item that sets its share of the container's free space.

Instead of calculating a width, tell the item that should fill the bar to grow.

  • flex-grow: 1 on Search gives it a share of the free space. It is the only item that grows, so the share is all 300px.
  • Logo and Login keep the default flex-grow: 0 and stay at 100px.
  • No width is calculated, and the HTML stays exactly as it was.

Now Search is 400px wide and the bar is full. If the bar becomes 800px wide, Search becomes 600px without any change in the CSS.

Example 2: One item takes all the free space

Assumption: This example uses standard CSS supported by all modern browsers, and assumes a row direction with no gap and no margins.

<!-- HTML (only the second item changes) -->
<div class="bar-item search">Search</div>

/* CSS */
.bar {
    display: flex;
    width: 600px;
}

.bar-item {
    width: 100px;
    height: 40px;
    background: #E2E8F0;
}

.search {
    flex-grow: 1;
}

Expected output

|AAAAABBBBBBBBBBBBBBBBBBBBCCCCC|
|AAAAABBBBBBBBBBBBBBBBBBBBCCCCC|

Free space = 600 - (100 + 100 + 100) = 300px.
Search is the only growing item, so it receives all 300px.
Search width = 100px + 300px = 400px.
Logo (A) and Login (C) stay at 100px.

Notice the difference. The container rule stays simple, and one declaration on one item makes it fill the bar.

Animation 2: The flex-grow design

One growing item, two fixed items

Two items keep their base size, and one item takes the free space.

🏷️Logoflex-grow: 0Stays 100px
🔍Searchflex-grow: 1Takes the free space
🔑Loginflex-grow: 0Stays 100px
 
 
 
.barfree space: 600 − 300 = 300px
.searchflex-grow: 1
.search (result)100px + 300px = 400px
Free space shared by growth

The animation highlights the free space and the one item that receives it.

Compare both approaches

Fixed widths only compared with flex-grow
Fixed widths only With flex-grow
Leftover space stays empty. Leftover space is shared among the growing items.
Filling a row needs a calculated width. Filling a row is one declaration.
A new container width means editing widths. The item adjusts when the container resizes.
A sibling that changes size means recalculating. The growing item takes whatever space remains.
Layout intent is hidden in numbers. Layout intent is clear: this item fills the space.

The idea to remember

  • Free space = the container's main size minus the base sizes of the items (and any gaps and margins).
  • flex-grow = set on a flex item. It sets the item's share of the free space. The default is 0.
  • Value = a unitless number that is zero or higher. Units and negative numbers are invalid.
  • Proportional = free space is divided in proportion to the flex-grow values, not to the item sizes.
  • Added to the base size = final size is the base size plus the share, so equal values do not always give equal widths.

S4. Step-by-Step Code Breakdown

1. Start with a flex item and its free space

flex-grow is set on a flex item, which is a direct child of a flex container. The parent needs display: flex or display: inline-flex. It works on the main axis, so it changes width in a row and height in a column.

Before any item grows, the browser starts from each item's base size. That is the flex-basis value, or the width in a row when flex-basis is auto. Then it works out the free space: the container's main size minus the base sizes, the margins and any gap. Only a positive amount can be shared.

The common values of flex-grow
Value What the item gets Typical use
0 No share. The item stays at its base size (the default). Logos, icons and buttons
1 One share of the free space The one item that fills the row
2, 3, and so on That many shares, compared with the other items A main area next to a smaller one
0.4 A fraction. If all values add up to less than 1, only that fraction of the free space is shared. Partial growth
negative or with a unit, such as -1 or 1px Invalid. The browser ignores the declaration. Not used

2. Share the free space in proportion

When several items grow, the browser adds up their flex-grow values, divides the free space by that total to get the size of one share, and gives each item its number of shares. In the next example, the container is 600px wide and each item has a 100px base size, so the free space is 300px.

Example 3: Growth values of 1, 2 and 0

<!-- HTML -->
<div class="bar">
    <div class="bar-item a">A</div>
    <div class="bar-item b">B</div>
    <div class="bar-item c">C</div>
</div>

/* CSS */
.bar { display: flex; width: 600px; }
.bar-item { width: 100px; height: 40px; }

.a { flex-grow: 1; }
.b { flex-grow: 2; }
.c { flex-grow: 0; }

Expected output

|AAAAAAAAAABBBBBBBBBBBBBBBCCCCC|

Free space = 600 - 300 = 300px.
Total of the growth values = 1 + 2 + 0 = 3.
One share = 300px / 3 = 100px.
A = 100px + 1 share = 200px
B = 100px + 2 shares = 300px
C = 100px + 0 shares = 100px (the output is shown as one row)

3. Compare flex-grow: 1 with flex: 1

Because the share is added to the base size, items with different base sizes stay different even when every item has flex-grow: 1. The shorthand flex: 1 also sets the base size to 0%. Every item then starts from zero, so all the space is shared and the items end up equal. Here the base sizes are 80px, 160px and 120px, and the free space is 240px.

Example 4: The same growth value with two different starting points

<!-- HTML -->
<div class="row grow">
    <span class="a">A</span>
    <span class="b">B</span>
    <span class="c">C</span>
</div>
<div class="row shorthand">
    <span class="a">A</span>
    <span class="b">B</span>
    <span class="c">C</span>
</div>

/* CSS */
.row { display: flex; width: 600px; }

.a { width: 80px; }
.b { width: 160px; }
.c { width: 120px; }

.grow span { flex-grow: 1; }
.shorthand span { flex: 1; }

Expected output

flex-grow: 1 on each item
|AAAAAAAABBBBBBBBBBBBCCCCCCCCCC|

flex: 1 on each item
|AAAAAAAAAABBBBBBBBBBCCCCCCCCCC|

First row: free space = 600 - 360 = 240px, one share per item = 80px.
Widths are 160px, 240px and 200px, because the base sizes differ.
Second row: the base size is 0, so each item gets 200px.
The width values are ignored in the second row.

4. Use a fraction of the free space

The value does not have to be a whole number. When the growth values add up to less than 1, the items share only that fraction of the free space, and the rest stays empty. Here only Search grows, with a value of 0.4.

Example 5: A growth value below 1

/* CSS (same HTML and base sizes as Example 1) */
.bar { display: flex; width: 600px; }
.bar-item { width: 100px; height: 40px; }

.search { flex-grow: 0.4; }

Expected output

|AAAAABBBBBBBBBBBCCCCC         |

Free space = 300px.
Search takes 0.4 of it: 0.4 x 300px = 120px.
Search width = 100px + 120px = 220px.
The remaining 180px stays empty on the right (the output is shown as one row).

5. Know what limits growth

An item stops growing when it reaches its max-width. The space it could not use is shared among the other growing items. In this example, Search has a maximum of 160px.

Example 6: A growing item with a maximum width

/* CSS (Logo has no flex-grow) */
.bar { display: flex; width: 600px; }
.bar-item { width: 100px; height: 40px; }

.search {
    flex-grow: 1;
    max-width: 160px;
}

.login { flex-grow: 1; }

Expected output

|AAAAABBBBBBBBCCCCCCCCCCCCCCCCC|

Free space = 300px, shared equally by Search and Login (150px each).
Search would reach 250px, but its max-width is 160px, so it stops at 160px.
That uses only 60px of its share, and the other 240px goes to Login.
Login width = 100px + 240px = 340px (the output is shown as one row).

6. Grow in a column

With flex-direction: column, the main axis is vertical, so flex-grow changes the height. The container must be taller than its content, otherwise there is no free space to share. A fixed height or a min-height creates it.

Example 7: A page where the main area fills the height

<!-- HTML -->
<div class="page">
    <header class="top">Header</header>
    <main class="content">Main</main>
    <footer class="bottom">Footer</footer>
</div>

/* CSS */
.page {
    display: flex;
    flex-direction: column;
    height: 300px;
}

.top, .bottom { height: 40px; }
.content { flex-grow: 1; }

Expected output

+------------------------+
| Header           40px  |
+------------------------+
| Main            220px  |
| (grows)                |
|                        |
+------------------------+
| Footer           40px  |
+------------------------+

Free space = 300 - (40 + 0 + 40) = 220px, and Main is its only growing item.
The diagram is not drawn to scale.
Real pages often use min-height: 100vh instead of a fixed height.

Notice that Main has no height of its own, so its base size is its content height. If the content were taller than 220px, it would need to be handled with overflow or a larger container.

S5. Architecture and Real-World Trade-Offs

Growth is set per item, so each part of a page can decide which item takes the leftover space. This is useful in toolbars, page layouts and card rows.

How the design fits a website

Imagine a website with a toolbar, a page layout and a row of cards. Each one has a fixed part and one part that expands.

A focused growth flow

Each website area decides which item takes the leftover space.

🧰ToolbarSearch field fills the space between two buttons
📐Page layoutMain content fills the space beside a fixed sidebar
🃏Card rowCards share the row equally
 
 
 
.searchflex-grow: 1
.mainflex-grow: 1
.cardflex: 1

The animation traces each website area to the rule that lets its item expand.

Benefits for larger websites

  • Maintainability: The expanding item is one small rule, and it needs no recalculation when siblings change.
  • Responsive layouts: The item adjusts to any container width without media queries for that purpose.
  • No extra markup: You do not need wrapper elements or spacer elements to fill space.
  • Clear intent: A flex-grow rule shows which item is meant to absorb the extra space.
  • Safe defaults: Items that set nothing keep flex-grow: 0 and stay at their base size.

Important trade-offs

  • flex-grow only works with positive free space. When the items are already wider than the container, nothing can grow, and flex-shrink takes over.
  • Growth values are shares of free space, not final sizes. Equal values give equal widths only when the base sizes are equal, for example with flex: 1.
  • Gaps and margins are subtracted before the free space is shared.
  • A max-width or max-height stops growth, and the unused space goes to the other growing items.
  • When growing items use all the free space, justify-content has nothing left to distribute.
  • With flex-wrap: wrap, free space is calculated for each line, so a last line with one growing item can stretch across the whole row.
  • flex-grow works on the main axis only. To fill the cross axis, use align-items: stretch or align-self.

Important: flex-grow shares only the leftover space. It does not set sizes. The base size, the container size and any maximum all affect the final result, so check the free space first when an item does not look the way you expect.

S6. Common Mistakes and Best Practices

Mistake 1: Expecting flex-grow: 2 to make an item twice as wide

Wrong: Give one item flex-grow: 2 and another flex-grow: 1, and expect a 2:1 width ratio.

Why it fails: The values divide the free space, and each share is added to the item's base size. Items with different base sizes will not end up in a 2:1 ratio.

Better: Use flex: 2 and flex: 1, so both items start from a base size of 0 and the free space is the full width.

Rule: flex-grow shares leftover space. It does not set proportions of the whole.

Mistake 2: Growing in a column without a container height

Wrong: Set flex-direction: column and flex-grow: 1, but leave the container's height as auto.

Why it fails: An auto-height container is only as tall as its content, so there is no free space to share.

Better: Give the container a height or a min-height, such as min-height: 100vh for a full page.

Rule: No free space means nothing to grow into.

Mistake 3: Setting flex-grow on an element that is not a flex item

Wrong: Add flex-grow: 1 to an element inside a flex item, or to a child of a parent without display: flex.

Why it fails: flex-grow only works on direct children of a flex container. Anywhere else it is ignored.

Better: Put display: flex on the parent and the rule on its direct child.

Rule: Check the parent before you debug the item.

Mistake 4: Using a unit or a negative number

Wrong: Write flex-grow: 1px, flex-grow: 50% or flex-grow: -1.

Why it fails: The value must be a unitless number that is zero or higher. Anything else is invalid, so the browser drops the declaration and the item keeps the default 0.

Better: Use a plain number such as 1, 2 or 0.5. To set a size, use flex-basis or width.

Rule: flex-grow is a ratio, not a length.

Mistake 5: Expecting flex-grow: 1 to give equal columns

Wrong: Put flex-grow: 1 on three cards with different content and expect three equal columns.

Why it fails: With a base size of auto, each card starts at the width of its content. Each card gets the same extra amount, so the cards stay unequal.

Better: Use flex: 1. Equal padding and borders keep the columns equal.

Rule: Equal columns need an equal starting point.

S7. How This Comes Up in Interviews

Question 1: What does flex-grow do?

What the interviewer wants: They want to know whether you understand free space and shares.

Strong answer:

"flex-grow is set on a flex item. It tells the browser how much of the container's leftover space on the main axis the item should receive. The default is 0, so items do not grow. When several items grow, the free space is divided in proportion to their values and added to their base sizes."

Question 2: What is the difference between flex-grow: 1 and flex: 1?

Strong answer:

"flex-grow: 1 only sets the growth value and leaves the base size as auto, so items start at their content or width size and stay unequal. flex: 1 is a shorthand for 1 1 0%. The base size is 0, so all the space is shared and the items end up equal."

Question 3: Three items have flex-grow values of 1, 2 and 3 in a 600px container. Each has a 100px base size. What are the widths?

Strong answer:

"The free space is 600 minus 300, which is 300px. The values add up to 6, so one share is 50px. The widths are 100 plus 50, 100 plus 100, and 100 plus 150, which gives 150px, 200px and 250px."

Question 4: An item has flex-grow: 1, but it does not expand. What do you check?

Strong answer:

"I check that the parent has display: flex and that the item is a direct child. Then I check that there is free space, because the items may already fill the container. In a column, the container needs a height. I also look for a max-width, and for flex-wrap, since free space is calculated for each line."

What should different experience levels explain?

  • Junior developer: Explain what flex-grow does and show one item that fills the leftover space.
  • Senior developer: Explain base size plus share, the difference from flex: 1, fractions below 1, and how max-width redistributes space.
  • Technical architect: Explain how growth conventions, such as flex: 1 for equal columns and one filling region per row, keep components predictable across a design system.

S8. Hands-On Practice

Beginner: Fill the bar

Create a 600px wide flex container with three items, each 100px wide. Add flex-grow: 1 to the middle item and observe the result.

Expected result: The first and last items stay at 100px, and the middle item becomes 400px wide.

Intermediate: Predict the widths

Use the same container and give the three items the values 1, 2 and 3. Write down the widths you expect, then open the page and compare. Next, change all three items to flex: 1 and compare again.

Hint: Work out the free space and the size of one share first.

Advanced: Build a page layout and test its limits

Build a column layout with a header, a main area and a footer, using min-height: 100vh on the container and flex-grow: 1 on the main area. Test it with very little content and with a lot of content. Then add a max-width to one growing item in a row and predict where the extra space goes.

Expected result: The footer stays at the bottom of the viewport when the content is short, and the page scrolls normally when the content is long. The space an item cannot use is given to the other growing items.

S9. Next Steps and Community

Previous article: Align Self and Order – Controlling Individual Flex Items.

Next article: Flex Shrink – Controlling How Items Compress.

Continue the series by learning how flex-shrink lets items compress when there is not enough space on the main axis, and how that shortage is shared between the items.

Try the examples in your own HTML and CSS project. Change the growth values, switch between flex-grow: 1 and flex: 1, test a max-width, and share your layouts with the Upgradix community. Help other developers understand Flexbox through practical examples.

Measure the free space. Then share it.

Upgradix by Shrash Studio
Learn Technology. Build Your Future.
Quality Technology Education. Completely Free.

Comments & Ratings (0)

Log in or create a student account to comment and rate this article.

Be the first to comment on this article.