Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

flex-grow — sharing free space

The flex-grow property controls how a flex item participates in distributing positive free space along the main axis. Its factors describe size increases, not the proportions of final widths.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

flex-grow: <number [0,∞]>;

flex-grow sets a flex item's growth factor. It accepts a unitless number greater than or equal to 0; percentages and negative numbers are invalid. Its initial value is 0, and it is not inherited.

Positive free space is distributed within each flex line along the main axis according to growth factors. 0 disables this growth. If the factors total less than 1, some space can remain unused.

The proportions apply to increases beyond base sizes, not final sizes. The result also depends on flex-basis and minimum and maximum constraints. flex-shrink controls shrinking. The flex shorthand sets these components together and resets omitted components.

In the example, the container is 500px wide, with two bases of 100px each. The remaining 300px is divided in a 1:2 ratio: the items gain 100px and 200px. Their expected widths are therefore 200px and 300px.

Examples

<!doctype html>
<meta charset="utf-8">
<title>flex-grow</title>
<style>
  .row { display: flex; width: 500px; }
  .item { flex-basis: 100px; flex-shrink: 0; min-width: 0; }
  #a { flex-grow: 1; background: lightblue; }
  #b { flex-grow: 2; background: lightgreen; }
</style>
<div class="row">
  <div class="item" id="a">A</div>
  <div class="item" id="b">B</div>
</div>
<pre id="result"></pre>
<script>
  const widths = ['a', 'b'].map(id =>
    document.getElementById(id).getBoundingClientRect().width
  );
  document.getElementById('result').textContent = widths.join(', ');
</script>

Result

200, 300

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources