Mastering Flexbox Items: `grow`, `shrink`, & `basis`

Discover the three key properties that give flex items their power and flexibility. Learn to control space, size, and responsiveness.

Lesson ProgressStep 1 of 11
Item 1
Item 2
Item 3
0 EXP

Welcome! Let's see how to control items inside a flex container. We have three items.

.container {
  display: flex;
  gap: 10px;
}
.item {
  width: 100px;
}

The `flex-grow` Property

The `flex-grow` property defines an item's ability to "grow" and take up any available **extra space** in the flex container. It accepts a unitless number that acts as a proportion.

  • flex-grow: 0: (Default) The item will not grow.
  • flex-grow: 1: The item will take up a proportional share of the empty space.
.item-1 {
  flex-grow: 1;
}
.item-2 {
  flex-grow: 2;
}
/* .item-2 will grow twice as much as .item-1 */

System Check

What value prevents a flex item from growing, even if there is extra space?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🏆
Flex Grow Guru

Master the `flex-grow` property to distribute space.

🏗️
Flex Shrink Savant

Correctly apply `flex-shrink` to prevent overflow.

✍️
Flex Basis Boss

Define `flex-basis` with pixel-perfect precision.

🏅
Shorthand Champion

Combine all three properties using the `flex` shorthand.

Mission: Build a Flexible Layout

You have a container and three items. Your mission:
1. Make `.item-2` (blue) grow to fill all remaining empty space.
2. Make `.item-1` (red) *never* shrink, even if the container is small.

Live Preview:

A.D.A. Feedback:

> System integrity looks stable. All objectives met.

Challenge: Order the Shorthand

The `flex` shorthand property combines three properties. Drag them into the correct order they appear in the shorthand.

flex:
`flex-shrink`
`flex-basis`
`flex-grow`
;

Challenge: Complete the `flex-basis`

Fill in the blanks for common `flex-basis` values.

flex-basis: ; /* Respects the item's `width` property */
flex-basis: ; /* Smallest possible size, good for growing */
flex-basis: ; /* A specific length value */

Consult A.D.A.

Community Holo-Net

Peer Project Review

Submit your "Flexible Layout" project from the code editor challenge for feedback from other Net-Runners.

The Three Negotiators: Mastering `flex-grow`, `shrink`, & `basis`

If `display: flex` is the boss that creates the team, then `flex-grow`, `flex-shrink`, and `flex-basis` are the three negotiators that decide how the team members (the flex items) share their resources (the space in the container). Mastering them is the difference between a layout that *works* and a layout that is truly *resilient* and *responsive*.

1. `flex-basis`: The Starting Offer

`flex-basis` is the first and most important negotiator. It defines the ideal starting size of an item *before* any growing or shrinking happens. Think of it as an item's opening bid: "I'd *like* to be this big."

  • flex-basis: 150px: The item wants to be 150px wide (if in a row).
  • flex-basis: 25%: The item wants to be 25% of the container's width.
  • flex-basis: auto: (The default) The item says, "Just use my `width` or `height` property as my starting size." If neither is set, it sizes to its content.
  • flex-basis: 0: The item says, "I'll start with no size and let `flex-grow` determine my final size." This is key for making items grow based *only* on their grow-factor, not their content.

Key Rule: If `flex-basis` is set to anything other than `auto`, it **overrides** the `width` or `height` property in that direction.

2. `flex-grow`: Dividing the Riches (Positive Space)

`flex-grow` decides what happens when there is **extra space** in the container. It's a number that represents a *proportion* or *ratio*.

  • flex-grow: 0: (The default) The item **refuses** to grow. It will stay at its `flex-basis` size.
  • flex-grow: 1: The item will take a share of the extra space. If all items have `flex-grow: 1`, they share the extra space equally.

Example: You have 300px of extra space.

  • Item A: `flex-grow: 1`
  • Item B: `flex-grow: 2`
  • Item C: `flex-grow: 1`

The total "grow factors" are 1 + 2 + 1 = **4 shares**. The 300px is divided into 4 shares (75px each).
- Item A gets 1 share (75px).
- Item B gets 2 shares (150px).
- Item C gets 1 share (75px).

3. `flex-shrink`: Sharing the Burden (Negative Space)

`flex-shrink` decides what happens when there is **not enough space** and items overflow. It determines how much an item is *willing* to shrink.

  • flex-shrink: 1: (The default) The item **agrees** to shrink proportionally with other items to prevent overflow.
  • flex-shrink: 0: The item **refuses** to shrink. It will stay at its `flex-basis` size, even if it overflows the container. This is extremely useful for logos, icons, or fixed-width sidebars.

The math for shrinking is more complex (it's weighted by the item's size), but the main takeaway is: **`flex-shrink: 0` means "do not shrink, ever."**

The `flex` Shorthand: Common Prescriptions

You will rarely write the three properties separately. Instead, you'll use the `flex` shorthand: flex: [grow] [shrink] [basis].

flex: 1;

/* Expands to:
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 0%;
*/

The "Equal Share": This tells an item to start at zero size and take an equal share of all available space. Perfect for equal-width columns.

flex: auto;

/* Expands to:
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: auto;
*/

The "Default Flexible": This tells an item to use its content size (`auto`), but feel free to grow or shrink from there.

flex: none;

/* Expands to:
  flex-grow: 0;
  flex-shrink: 0;
  flex-basis: auto;
*/

The "Rigid Item": This tells an item to use its content size and *never* grow or shrink.

flex: 1 1 250px;

/* Expands to:
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 250px;
*/

The "Responsive Card": The most common pattern for grids. "Try to be 250px, but grow or shrink if you need to."

Key Takeaway: Use `flex-basis` to set the ideal size, `flex-grow` to distribute extra space, and `flex-shrink` to control what happens in tight spaces. Use the `flex` shorthand to set them all at once.

Flex Item Properties Glossary

flex-grow
A unitless number that defines an item's ability to grow if there is extra space in the container. A value of `0` (the default) prevents growing. A value of `1` (or higher) allows the item to take up a proportional share of the available free space.
flex-shrink
A unitless number that defines an item's ability to shrink if there is not enough space in the container. The default value is `1`, which allows the item to shrink. A value of `0` prevents the item from shrinking, and it will retain its `flex-basis` size even if it causes overflow.
flex-basis
Defines the "ideal" starting size of a flex item *before* any growing or shrinking occurs. It can be a length (e.g., `150px`, `10rem`, `25%`) or a keyword.
  • auto: (Default) Uses the item's `width` or `height` property (or its content size if not set).
  • 0: Starts the item with no size, forcing its size to be determined purely by `flex-grow` and the available space.
  • content: Sizes the item based on its content.
flex (Shorthand)
The powerful shorthand property that combines `flex-grow`, `flex-shrink`, and `flex-basis` in that specific order. Example: `flex: 1 0 200px;` (grow, don't shrink, start at 200px).
flex: 1
A common "magic" shorthand value that expands to `flex: 1 1 0%`. It tells an item to start at zero size (`0%`), but grow (`1`) and shrink (`1`) as needed. This is the best way to create equal-width columns.
flex: auto
A shorthand value that expands to `flex: 1 1 auto`. It tells an item to start at its default size (`auto`), but be flexible by growing (`1`) and shrinking (`1`) if necessary.
flex: none
A shorthand value that expands to `flex: 0 0 auto`. This creates a rigid, inflexible item that will not grow (`0`) and will not shrink (`0`), staying at its default `auto` size.
Flex Item
A direct child element of a flex container. These are the elements that the `flex-grow`, `flex-shrink`, and `flex-basis` properties apply to.
Flex Container
The parent element that has `display: flex` or `display: inline-flex` applied, establishing the flex formatting context for its children.
Positive / Free Space
The extra space within a flex container along the main axis, available after all flex items have been sized to their `flex-basis`. `flex-grow` determines how this space is distributed.
Negative Space
The amount of space that needs to be removed from items when their combined `flex-basis` sizes are larger than the flex container. `flex-shrink` determines how items are shrunk to fit this space.
Main Size
An item's `width` or `height`, depending on the `flex-direction`. If `flex-direction: row`, the main size is the width. If `flex-direction: column`, the main size is the height. `flex-basis` is a substitute for the main size property.

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching CSS and building robust, responsive web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest CSS Flexible Box Layout Module Level 1 specifications.

External Resources

Found an error or have a suggestion? Contact us!