CSS flex-grow Property
Subject: css
CSS flex-grow Property
The flex-grow property defines how much a flex item should grow relative to other items inside a flex container when extra space is available.
Why Use flex-grow?
- Automatically scale items to fill available space
- Distribute space proportionally among items
- Avoid fixed widths in responsive design
- Improve layout flexibility with fewer media queries
Syntax
<number> is a unitless value, typically 0, 1, or any positive number.
How It Works
flex-grow: 0(default) → item does not growflex-grow: 1+→ item grows based on proportion
When extra space is available, it's distributed according to the flex-grow value:
- An item with
flex-grow: 2will take twice as much space as an item withflex-grow: 1
Example: Unequal Growth
Explanation:
item1gets 1 part of extra spaceitem2gets 2 partsitem3gets 3 parts
If 60% of space is available, distribution would be 10%, 20%, and 30% respectively.
Best Practices
- Use
flex-grow: 1for equal item sizing - Use higher values to prioritize space allocation
- Combine with
flex-basisfor better control - Always apply
display: flexto the container
Common Use Cases
- Responsive navbars
- Dynamic card grids
- Sidebars and flexible main content
- Equal-height and variable-width layouts
Key Takeaways
flex-growdetermines an item’s growth ratio- Default is
0(no growth) - Higher values grow more relative to others
- Only works if there is extra space in the container
- Use for fluid, scalable, and responsive designs
Advertisement Slot 1
Advertisement Slot 2