Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

column-fill — how columns are filled

The column-fill property controls sequential filling or balancing of column content. It also distinguishes balancing the last fragment from balancing every fragment, such as pages in printed output.

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

Syntax

column-fill: auto | balance | balance-all;

column-fill applies to multicol containers; it does not create columns itself. Its initial value is balance, it is not inherited, and its animation type is discrete.

auto specifies sequential filling; later columns can remain empty. In continuous layout with an indefinite container block size, Chromium can balance the columns despite column-fill: auto, whereas Firefox can put all the content in the first column. balance distributes content as evenly as possible. In fragmented contexts, such as pages, it balances only the last fragment. balance-all balances every fragment. A specification definition does not confirm target-browser support for balance-all.

Balancing respects forced breaks, widows, orphans, and unbreakable content, so equal text lengths are not guaranteed. Multi-column lines immediately before an element spanning columns are not controlled by this property. In continuous contexts, the property has no effect when overflow columns exist.

The example fixes the container height to expose the difference: auto fits four items in the first column, while balance distributes two into each. When the example ran in an isolated Chromium environment, its console output exactly matched the stated result.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Sequential and balanced column filling</title>
  <style>
    .columns {
      inline-size: 20rem;
      block-size: 5rem;
      column-count: 2;
      column-gap: 1rem;
      outline: 1px solid;
    }
    .columns > div {
      block-size: 1.25rem;
      line-height: 1.25rem;
      break-inside: avoid;
    }
    .sequential { column-fill: auto; }
    .balanced { column-fill: balance; }
  </style>
</head>
<body>
  <section aria-labelledby="sequential-heading">
    <h2 id="sequential-heading">Sequential filling</h2>
    <div class="columns sequential">
      <div>A</div><div>B</div><div>C</div><div>D</div>
    </div>
  </section>
  <section aria-labelledby="balanced-heading">
    <h2 id="balanced-heading">Balanced filling</h2>
    <div class="columns balanced">
      <div>A</div><div>B</div><div>C</div><div>D</div>
    </div>
  </section>
  <script>
    for (const container of document.querySelectorAll('.columns')) {
      const style = getComputedStyle(container);
      const byLeft = new Map();
      for (const item of container.children) {
        const { left } = item.getBoundingClientRect();
        if (!byLeft.has(left)) byLeft.set(left, []);
        byLeft.get(left).push(item.textContent);
      }
      const columns = [...byLeft.keys()].sort((a, b) => a - b)
        .map(left => byLeft.get(left));
      while (columns.length < Number(style.columnCount)) columns.push([]);
      const distribution = columns.map(items => `[${items.join(' ')}]`).join(' | ');
      console.log(`${style.columnFill}: ${distribution}`);
    }
  </script>
</body>
</html>

Result

auto: [A B C D] | []
balance: [A B] | [C D]

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