W3docs

CSS grid-column-gap Property

The grid-column-gap CSS property defines the size of the gap between the columns. See property description, values and examples.

The grid-column-gap property sets the size of the gap between the columns in a CSS Grid layout.

Length can be specified both by pixels and percentages.

Warning

The grid-column-gap property is deprecated. Use the modern column-gap property or the gap shorthand instead. Negative values are not allowed.

Initial Value0
Applies toGrid containers.
InheritedNo.
AnimatableYes. Gap is animatable.
VersionCSS Grid Layout Module Level 1
DOM Syntaxobject.style.gridColumnGap = "30px";

Syntax

Syntax of CSS grid-column-gap Property

grid-column-gap: length;

Example of the grid-column-gap property:

Example of CSS grid-column-gap Property with length value

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .grid-container {
        display: grid;
        grid-template-columns: auto auto auto auto;
        grid-column-gap: 30px;
        grid-row-gap: 10px;
        background-color: #666;
        padding: 10px;
      }
      .grid-container > div {
        background-color: #ccc;
        text-align: center;
        padding: 20px 0;
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <h2>Grid-column-gap property example</h2>
    <div class="grid-container">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
      <div>6</div>
      <div>7</div>
      <div>8</div>
      <div>9</div>
      <div>10</div>
      <div>11</div>
      <div>12</div>
    </div>
  </body>
</html>

Result

CSS grid-column-gap Property

Example of the grid-column-gap property with the "%" value:

Example of CSS grid-column-gap Property with % value

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .grid-container {
        display: grid;
        grid-template-columns: auto auto auto auto;
        grid-column-gap: 20%;
        grid-row-gap: 10px;
        background-color: #666;
        padding: 10px;
      }
      .grid-container > div {
        background-color: #ccc;
        text-align: center;
        padding: 20px 0;
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <h2>Grid-column-gap property example</h2>
    <div class="grid-container">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
      <div>6</div>
      <div>7</div>
      <div>8</div>
    </div>
  </body>
</html>

Values

ValueDescriptionPlay it
lengthThe gap between columns is specified by pixels or percentages. Negative values are not allowed.Play it »
initialMakes the property use its default value.
inheritInherits the property from its parent element.

Practice

Practice

What is the purpose of the 'column-gap' property in CSS grid layout?