W3docs

CSS flex-grow Property

The flex-grow property defines how much the item will grow. See the values of this property and try some examples.

The flex-grow property specifies how much the item will grow relative to the rest of items in the flex container. If all items in the container have a flex-grow factor set, they divide the remaining free space proportionally based on their factors. A flexible item’s main size is either its height or width, which depends on the value of flex-direction.

This property is one of the CSS3 properties. It is used with the flex-shrink and flex-basis properties.

Info

If there are no flexible items, flex-grow property won't have any effect.

Initial Value0
Applies toFlex items, including in-flow pseudo-elements.
InheritedNo.
AnimatableYes. Items are animatable.
VersionCSS3
DOM Syntaxobject.style.flexGrow = 3;

Syntax

Syntax of CSS flex-grow Property

flex-grow: number | initial | inherit;

Example of the flex-grow property:

Example of CSS flex-grow Property with number value

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .box {
        width: 320px;
        height: 120px;
        border: 2px solid #cccccc;
        display: flex;
      }
      .box div:nth-of-type(1) {
        flex-grow: 1;
      }
      .box div:nth-of-type(2) {
        flex-grow: 2;
      }
      .box div:nth-of-type(3) {
        flex-grow: 1;
      }
      .box div:nth-of-type(4) {
        flex-grow: 1;
      }
      .box div:nth-of-type(5) {
        flex-grow: 1;
      }
    </style>
  </head>
  <body>
    <h2>Flex-grow property example</h2>
    <div class="box">
      <div style="background-color: #eeeeee;"></div>
      <div style="background-color: #1c87c9;"></div>
      <div style="background-color: #8ebf42;"></div>
      <div style="background-color: #cccccc;"></div>
      <div style="background-color: #666666;"></div>
    </div>
  </body>
</html>

Result

CSS flex-grow Property

Example of the flex-grow property with a higher growth factor:

CSS flex-grow property with a number as a value

<!DOCTYPE html>
<html>
  <head>
    <title>The title of the document</title>
    <style>
      .box {
        width: 320px;
        height: 120px;
        border: 2px solid #cccccc;
        display: flex;
      }
      .box div:nth-of-type(1) {
        flex-grow: 1;
      }
      .box div:nth-of-type(2) {
        flex-grow: 6;
      }
      .box div:nth-of-type(3) {
        flex-grow: 1;
      }
      .box div:nth-of-type(4) {
        flex-grow: 1;
      }
      .box div:nth-of-type(5) {
        flex-grow: 1;
      }
    </style>
  </head>
  <body>
    <h2>Flex-grow property example</h2>
    <div class="box">
      <div style="background-color: #eeeeee;"></div>
      <div style="background-color: #1c87c9;"></div>
      <div style="background-color: #8ebf42;"></div>
      <div style="background-color: #cccccc;"></div>
      <div style="background-color: #666666;"></div>
    </div>
  </body>
</html>

Values

ValueDescriptionPlay it
numberSpecifies how much the item will grow relative to the rest of flexible items of the same container. Default value is 0.Play it »
initialSets the property to its default value.Play it »
inheritInherits this property from its parent element.

Practice

Practice

What is the function of the 'flex-grow' property in CSS?