Set how much a flex item will grow relative to the rest of the flex items with CSS

The CSS flex-grow property controls how much a flex item will grow relative to the rest of the flex items inside a flex container. When there's extra space available, this property determines how that space is distributed among flex items.

Syntax

selector {
    flex-grow: number;
}

Possible Values

Value Description
0 Default value. Item will not grow.
number A positive number that defines the growth factor relative to other flex items.

Example: Basic Flex Grow

The following example demonstrates how flex-grow distributes extra space. The third item (Q3) has a higher grow value, making it larger than other items −

<!DOCTYPE html>
<html>
<head>
<style>
    .mycontainer {
        display: flex;
        background-color: orange;
        padding: 10px;
        gap: 5px;
    }
    .mycontainer > div {
        background-color: white;
        text-align: center;
        line-height: 40px;
        font-size: 20px;
        min-width: 50px;
        border-radius: 5px;
    }
</style>
</head>
<body>
    <h2>Quiz Items with Flex Grow</h2>
    <div class="mycontainer">
        <div style="flex-grow: 1">Q1</div>
        <div style="flex-grow: 1">Q2</div>
        <div style="flex-grow: 3">Q3</div>
        <div style="flex-grow: 1">Q4</div>
        <div style="flex-grow: 1">Q5</div>
    </div>
</body>
</html>
An orange container with five white rounded boxes labeled Q1-Q5. The Q3 box is noticeably larger than the others, taking up three times more space due to its flex-grow: 3 value.

Example: Equal Distribution

When all items have the same flex-grow value, they grow equally to fill the available space −

<!DOCTYPE html>
<html>
<head>
<style>
    .equal-container {
        display: flex;
        background-color: #f0f0f0;
        padding: 10px;
        gap: 5px;
        margin-top: 20px;
    }
    .equal-container > div {
        background-color: #4CAF50;
        color: white;
        text-align: center;
        line-height: 40px;
        flex-grow: 1;
        border-radius: 5px;
    }
</style>
</head>
<body>
    <div class="equal-container">
        <div>Item 1</div>
        <div>Item 2</div>
        <div>Item 3</div>
        <div>Item 4</div>
    </div>
</body>
</html>
Four green boxes of equal width labeled "Item 1" through "Item 4" fill the container evenly, each taking up exactly 25% of the available space.

Conclusion

The flex-grow property is essential for creating flexible layouts where items can expand to fill available space. Use higher values to make items grow larger relative to their siblings.

Updated on: 2026-03-15T13:23:49+05:30

202 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements