Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

flex-basis — a flex item's base size

flex-basis sets an item's base size along the main axis, before flex layout distributes free space.

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

Syntax

flex-basis: content | <'width'>;

flex-basis applies to flex items, is not inherited, and initially equals auto. It specifies the main-axis base size, not necessarily the final size: growth, shrinkage, and minimum and maximum constraints also affect sizing.

auto retrieves width or height, depending on the main axis; if that is also auto, it uses content. The content value determines the basis from the content.

Percentages reference the container's inner main size; when that is indefinite, the used value is content. The basis normally sizes the content box, subject to box-sizing. The flex shorthand sets basis, growth, and shrinkage together.

Examples

<!doctype html>
<meta charset="utf-8">
<title>flex-basis</title>
<style>
  .container { display: flex; width: 300px; }
  .item { flex-grow: 1; flex-shrink: 0; min-width: 0; }
  #a { flex-basis: 60px; }
  #b { flex-basis: 120px; }
</style>
<div class="container">
  <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

120, 180

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