CSS

🎯 CSS grid-column-gap Property

The grid-column-gap property is used in CSS Grid Layout to define the horizontal spacing between columns.

By adjusting this value, you can control how much space appears between grid columns and create cleaner, more readable layouts.

  • 📌 Why Use grid-column-gap?

  • Improves readability by separating columns.
  • Creates cleaner and more professional grid layouts.
  • Allows flexible spacing using different CSS units.

🔹 grid-column-gap Values

1️⃣ length

Specifies the amount of space between columns using units such as px, rem, em, or percentages.

CSS

.container {
    grid-column-gap: 20px;
}
                

Creates a 20px horizontal gap between each grid column.

CSS

.container {
    grid-column-gap: 1rem;
}

.container {
    grid-column-gap: 5%;
}
                

2️⃣ initial

Resets the property to its default browser value.

CSS

.container {
    grid-column-gap: initial;
}
                

🧩 Practical Example

CSS

.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-column-gap: 30px;
}
                

In this example, the grid contains three equal-width columns with a 30px gap between each column.

  • ⚠️ Modern Alternative

  • The grid-column-gap property is now considered a legacy property.
  • Modern CSS uses the shorter column-gap or gap properties instead.
  • ✔️ Quick Summary

  • grid-column-gap defines the horizontal spacing between grid columns.
  • length values such as px, rem, em, and % can be used.
  • initial resets the property to its default value.
  • Modern projects usually prefer column-gap or gap.