Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

column-gap — spacing between columns

The column-gap property specifies spacing between grid or multicolumn columns; in flex layout, its meaning depends on the axis direction.

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

Syntax

column-gap: normal | <length-percentage [0,∞]> | <line-width>;

column-gap sets the gutter between grid columns and multicolumn columns. In a flex container with flex-direction: row, it separates items within a line; with flex-direction: column, it separates flex lines. It adds no spacing at the container’s outer edges and is not inherited.

Use a nonnegative length or percentage. The initial value, normal, has a used value of 1em in multicolumn layout and 0px in grid and flex. The draft grammar shown also includes <line-width>; do not assume support in the target browser.

Percentages refer to the corresponding dimension of the container’s content box. For a cyclic dependency, grid treats them as zero when determining intrinsic size contributions but resolves them when laying out content; flex treats them as zero.

row-gap controls spacing between rows; the shorthand gap: 8px 20px sets row-gap and column-gap, respectively. Content alignment can increase visible spacing. The example creates two 100px columns separated by 20px, with no extra space to distribute.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>column-gap</title>
<style>
  .grid {
    display: grid;
    grid-template-columns: 100px 100px;
    column-gap: 20px;
    width: 220px;
    direction: ltr;
    writing-mode: horizontal-tb;
  }
  .grid > div {
    height: 40px;
    background: lightblue;
  }
</style>
<div class="grid">
  <div>A</div>
  <div>B</div>
</div>
</html>

Result

A | 20px gap | B
Column widths: 100px, 100px. Grid content width: 220px.

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