Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

flex-shrink — the flex item shrink factor

flex-shrink controls a flex item's share of size reduction when its flex line lacks space. The item's base size also affects that share.

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

Syntax

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

flex-shrink controls a flex item's shrinking along the main axis. It accepts a nonnegative unitless number, including fractions; its initial value is 1. It is not inherited. A value of 0 disables flex shrinking, while negative values are invalid.

The space deficit is distributed using each factor multiplied by the item's inner flex base size. Thus, 2 alone does not guarantee twice as many pixels lost. Minimum and maximum size constraints can change the result; a content-based automatic minimum can block shrinking. In a horizontal layout, min-width: 0 removes that obstacle.

In the example, two 200px bases exceed 300px by 100px. The weights 1 × 200 and 3 × 200 produce reductions of 25px and 75px: the expected widths are 175px and 125px. The flex shorthand sets growth, shrinking, and basis together rather than leaving accidental earlier values in place.

Examples

<!doctype html>
<meta charset="utf-8">
<title>flex-shrink</title>
<style>
  .row { display: flex; width: 300px; }
  .item { flex: 0 1 200px; min-width: 0; }
  .item:last-child { flex-shrink: 3; }
</style>
<div class="row">
  <div class="item">A</div>
  <div class="item">B</div>
</div>
<pre id="result"></pre>
<script>
  const widths = [...document.querySelectorAll('.item')]
    .map(item => item.getBoundingClientRect().width);
  document.getElementById('result').textContent = widths.join(', ');
</script>

Result

175, 125

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