The Wayback Machine - https://web.archive.org/web/20240926140427/https://www.geeksforgeeks.org/css-grid-column-gap-property/
Open In App

CSS grid-column-gap Property

Last Updated : 27 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The grid-column-gap property in CSS is used to set the size of the gap between the columns in a grid layout. 

Syntax:

grid-column-gap: none | length | initial |inherit;

Property Values:

Property Value

Definition

none

It is used to set the grid-column-gap property to its default value. The default value of grid-column-gap is 0.

length

The size of the gap between columns is given in terms of length. The value of length can be in the form of px, em, etc. The value must be non-negative.

initial

It is used to set the grid-column-gap property to its default value.

inherit

This property is inherited from its parent.

Different Example of CSS Grid Column Property

Example 1: In this example, we are using the above-explained property.

html
<!DOCTYPE html>
<html>
  
<head>
    <title>
        CSS grid-column-gap Property
    </title>

    <style>
        .main {
            display: grid;
            grid-template-columns: auto auto auto;

            /* CSS property used here */
            grid-column-gap: 20px;
            grid-row-gap: 20px;
            background-color: green;
            padding: 30px;
        }

        .main>div {
            background-color: white;
            text-align: center;
            padding: 15px;
            font-size: 25px;
        }
    </style>
</head>

<body>
    <div class="main">
        <div>G</div>
        <div>E</div>
        <div>E</div>
        <div>K</div>
        <div>S</div>
    </div>
</body>
  
</html>

Output:

Example 2: This example describes the default grid-column-gap property. 

html
<!DOCTYPE html>
<html>
  
<head>
    <title>
        CSS grid-column-gap Property
    </title>

    <style>
        .main {
            display: grid;
            grid-template-columns: auto auto auto;

            /* CSS property used here */
            grid-column-gap: initial;
            grid-row-gap: 20px;
            background-color: green;
            padding: 30px;
        }

        .main>div {
            background-color: white;
            text-align: center;
            padding: 15px;
            font-size: 25px;
        }
    </style>
</head>

<body>
    <div class="main">
        <div>G</div>
        <div>E</div>
        <div>E</div>
        <div>K</div>
        <div>S</div>
    </div>
</body>
  
</html>

Output:

Supported browsers: The browser supported by CSS grid-column-gap property are listed below:

  • Google Chrome 57.0
  • Safari 10.0
  • Opera 44.0
  • Firefox 52.0

CSS grid-column-gap Property – FAQs

What is the grid-column-gap property used for in CSS?

The grid-column-gap property sets the spacing between columns in a grid container. It helps you manage the horizontal space between grid tracks, making it easier to create a well-spaced layout.

How can I set the space between columns in a grid?

You can set the column gap using: grid-column-gap: 20px; which creates a 20px space between each column.

Is grid-column-gap still recommended, or should I use gap?

While grid-column-gap is still supported, it is recommended to use the more versatile gap property instead, as it handles both row and column gaps in a single declaration.

Can I use percentage or fractional units with grid-column-gap?

Yes, you can use percentage or fractional units (fr) with grid-column-gap, allowing you to create responsive spacing that adapts based on the container’s width.

How does grid-column-gap interact with grid-template-columns?

Grid-column-gap works alongside grid-template-columns to maintain the specified space between columns, regardless of how many columns or their widths are defined.



Previous Article
Next Article

Similar Reads

CSS grid-gap Property
The grid-gap property sets the size of the gap between rows and columns in a grid layout, allowing you to easily control the spacing between grid items in both horizontal and vertical directions. It is a shorthand property for the following properties: grid-column-gap propertygrid-row-gap propertySyntax: grid-gap: grid-row-gap grid-column-gap;Prope
3 min read
CSS grid-row-gap Property
The grid-row-gap property in CSS is used to define the size of the gap between the grid elements. The user can specify the width of the gap separating the rows by providing a value to the grid-row-gap. Syntax: grid-row-gap: length | percentage | global-values;Property Values: length: The user can set the grid-row-gap value to be a fixed length meas
3 min read
CSS column-gap Property
The column-gap property in CSS is used to specify the amount of gap between the columns in which a given text is divided using the column-count property. Syntax: column-gap: length | normal | initial | inherit;Default Value: normal Property Values: Property Value Description length This value specifies the length that will set the gap between the c
3 min read
How to Specify Divider gap in Square Grid using Bootstrap ?
The CSS grid-row-gap property is used to set the size of the gap between the grid row elements. Similarly, the CSS grid-column-gap property is used to set the size of the gap (gutter) between the column elements. Syntax: CSS grid-column-gap propertygrid-column-gap: none|length|percentage|initial|inherit;CSS grid-row-gap propertygrid-row-gap: length
2 min read
How To Use Grid-Row-Align And Grid-Column-Align?
The grid-row-align and grid-column-align properties don't exist in CSS. Instead, CSS Grid uses properties like "align-items" and "justify-items" for controlling alignment across rows and columns, allowing precise positioning of grid items within their cells. so we will go to see how can we align the grid items. These are the following ways: Table o
3 min read
How to make a grid without calling CSS Grid property ?
In this article, we will see how to make a grid without calling CSS Grid property, along with understanding its implementation through the examples. It is essential to understand how CSS grid property works but what if we do not use the CSS grid property to make a grid. This is the generic question asked by the interviewer, which can give you a bet
4 min read
CSS gap Property
The CSS gap property defines the size of the gap between rows and columns in flexbox, grid, or multi-column layouts. It combines row-gap and column-gap into one property, allowing spacing to be set in length units (e.g., px, em) or percentages. Syntax gap: &lt;row-gap&gt; &lt;column-gap&gt;Property valuesProperty ValueDescription&lt;length&gt;Speci
2 min read
How to create two column grid and two column layout using jQuery Mobile ?
jQuery Mobile provides CSS-based columns that are responsive. The grids have a width of 100%, grids do not have a background color, border, and padding. The grids contain elements in them, these elements can be made float side-by-side using the ui-block-a or ui-block-b or ui-block-c or ui-block-d class. Columns in a grid are of equal width. In 2 co
2 min read
CSS grid-column Property
The CSS grid-column property specifies a grid item's size and location in a grid layout. It controls the placement and span of grid items, allowing the specification of starting and ending column lines. This enables flexible and responsive design without altering the HTML structure. Syntaxgrid-column: grid-column-start | grid-column-end;Property Va
4 min read
CSS grid-column-end Property
The CSS grid-column-end property specifies the ending position of a grid item within a grid layout. The grid-column-end property defines how many columns an item will span, or on which column line the item will end, allowing precise placement within the grid structure. Syntaxgrid-column-end: auto |span n | column-line;Property ValuesProperty Value
4 min read
CSS grid-column-start Property
The grid-column-start property in CSS defines the starting column line for a grid item within a grid container, offering significant layout flexibility. This property can utilize various values to control item placement, enhancing the responsive design of web pages. Syntaxgrid-column-start: auto | span n | column-line;Default Value: autoProperty Va
4 min read
Pure CSS Regular Grid vs Responsive Grid
Pure CSS is a free and open-source CSS framework. It is a collection of tools for creating online programs and responsive web pages. This was developed by Yahoo and is used to make websites that load faster, look better, and are easier to use. Bootstrap is effectively replaced by it. When developing Pure CSS, the responsive design was taken into ac
4 min read
Line-Based Placement of Grid Items with CSS Grid Layout
CSS Grid Layout is a flexible tool for designing web pages. One of its key features is line-based placement, which allows you to position items exactly where you want them using grid lines. This guide will explain different ways to use line-based placement in CSS. CSS Grid Layout divides a container into rows and columns, which are defined by grid
5 min read
How to Set the Gap Between Text and Underlining using CSS ?
Introduction: CSS is used to make the website visually more appealing and more readable. It can be used to format the text on the website in various ways like color, font-size, font-family, etc. In this article, we are going to see how in the case of underlined text, increase the gap between text and underline.Approach: The trick that we are going
1 min read
Tailwind CSS Gap
This class accepts more than one value in tailwind CSS all the properties are covered as in class form. It is the alternative to the CSS gap property. This class is used to set the spacing also caller gutter between the rows and columns. As like column-gap and row-gap using separately both so that one can use simply gap property that can given colu
3 min read
How to set length to set the gap between the columns in CSS ?
In this article, we will learn how to set the length that will set the gap between the columns. A web page's text content can be organized into many columns using CSS, which is a strong tool for web development. Long paragraphs of text can be divided into smaller, easier-to-read sections by using columns. Approach: The column-gap property is used t
3 min read
What is the purpose of using the Gap Classes in Tailwind CSS ?
Tailwind CSS Gap Classes such as gap-[size], are used to define the gap or spacing between grid or flex container child elements. These classes simplify the management of spacing, creating consistent layouts by controlling the space between elements horizontally (with gap-x-[size]) and vertically (with gap-y-[size]). Syntax:&lt;div class="grid grid
1 min read
Foundation CSS Flex Grid Column Alignment
Foundation CSS is an open-source and responsive front-end framework created by ZURB in September 2011 that makes it simple to create stunning responsive websites, apps, and emails that operate on any device. Many companies, like Facebook, eBay, Mozilla, Adobe, and even Disney, use it. It has numerous pre-built website component that makes our websi
8 min read
Primer CSS Grid Centering a Column
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by Object-Oriented CSS principles, functional CSS, an
2 min read
Primer CSS Grid Column Widths
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by Object-Oriented CSS principles, functional CSS, an
2 min read
How to make a grid with two columns where 1st column has 20% of width and 2nd one 80% width in Tailwind CSS ?
Tailwind CSS simplifies the process of making complex UI designs. It has a lot of predefined styles in form of classes, which can be applied to any HTML element in the code. Also, one advantage of Tailwind CSS is that during the production build, it analyzes the HTML components, and removes any unused CSS, hence decreasing the overall size of the C
4 min read
Tailwind CSS Grid Column Start / End
This class accepts more than one value in tailwind CSS all the properties are covered as in class form. It is the alternative of CSS grid-column property in CSS it was used to describes the number of properties that allow to design of grid structures and control the placement of grid items using Tailwind CSS. It can change the layout of grid items
3 min read
How to Create a 3-Column Layout Grid with CSS?
Grid in CSS is a powerful layout system that allows you to create complex, responsive designs with ease. By defining rows and columns, you can position elements precisely within a grid container. Using grid properties like grid-template-columns, you can create flexible and adaptive layouts, such as a 3-column design that adjusts to various screen s
3 min read
How to Create a 2-Column Layout Grid with CSS?
Creating a two-column layout is a common design pattern used in web development. This layout helps to organize content efficiently and is used across various types of websites. A 2-column layout divides the webpage into two sections, which can be useful for creating sidebars, main content areas, or other types of content distribution. These are the
4 min read
How to Create a 4-Column Layout Grid with CSS?
We can create a layout with multiple columns using CSS. It is easier to design complex layouts. In this article, we are going to discuss how to create a 4-column layout grid using CSS. We will discuss different approaches, their syntax, and code examples of each method. A 4-column layout grid is a common design structure used in web pages to neatly
4 min read
How to use grid element using the grid auto placement rules?
In this article, you will learn to use grid elements using the grid auto-placement rules. You can use auto as a property value on the grid to auto-enable the container to customize its size on the basis of the content of the items in the row or columns. Syntax: grid-template-rows : auto grid-template-columns: auto Property Value: auto : The size of
2 min read
Bootstrap 5 Grid system Grid tiers
Bootstrap Grid system is one of the most versatile layouts which we can use and it has different responsive variants which can be used to add custom responsiveness. Across the six default breakpoints, the grid works smoothly, and all these breakpoints can also be called Grid Tiers which can be changed using the SASS version. For this, we can use th
5 min read
Bulma Default Gap
In this article, we'll be seeing the Bulma Default gap. Bulma default gap is used in columns in which each column has the same or equal gap as of variable that has a value of 0.75rem. Bulma Default gap Class: There is no such specific class used but the column class can be used to give the gap between different columns. Syntax: &lt;div class="colum
1 min read
How to keep gap between columns using Bootstrap?
We can keep gap between columns by using normal CSS but here we will use the Bootstrap framework for that. In this article, we will keep a measured gap between columns by the following methods. Using "div" tag: Simply adding a "div" with padding in between two "div" tags gives spacing between the "div". Example: &lt;!DOCTYPE html&gt; &lt;html lang=
2 min read
Bulma Variable Gap
Bulma Variable Gap class is used to create defined gap between columns, there are 9 modifiers of options in this class. All the classes are mentioned and described below. This class can be used as column width. Bulma Variable Gap: is-0: This class removes the gap between classes. It is similar to the Gapless class.is-1: This class creates a gap bet
2 min read