Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS grid-column-gap Property

Posted in CSS Tutorial
Updated on Oct 03, 2024
By Mari Selvan
👁️ 41 - Views
⏳ 4 mins
💬 1 Comment
CSS grid-column-gap Property

Photo Credit to CodeToFun

🙋 Introduction

The grid-column-gap property in CSS is used to define the space (or gap) between the columns in a grid layout.

This property helps in creating a visually appealing and organized structure for grid-based layouts by ensuring consistent spacing between columns.

💡 Syntax

The syntax for the grid-column-gap property is simple and accepts a length value.

Syntax
Copied
Copy To Clipboard
container {
  grid-column-gap: value;
}

Here, value can be any valid CSS length unit, such as px, em, %, rem, etc.

🎛️ Default Value

The default value of the grid-column-gap property is 0. This means that, by default, there is no space between the columns in a grid layout.

🏠 Property Values

ValueDescription
lengthA length value specifying the size of the gap between columns, such as 10px, 1em, 5%, etc.

📄 Example

In this example, we'll create a simple grid layout with a column gap of 20px.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS grid-column-gap Example</title>
  <style>
    .grid-container {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      grid-column-gap: 20px;
    }
    .grid-item {
      background-color: #4CAF50;
      color: white;
      padding: 20px;
      text-align: center;
    }
  </style>
</head>
<body>
  <h1>Grid Layout with Column Gap</h1>
  <div class="grid-container">
    <div class="grid-item">1</div>
    <div class="grid-item">2</div>
    <div class="grid-item">3</div>
  </div>
</body>
</html>

🖥️ Browser Compatibility

The grid-column-gap property is well-supported in modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The grid-column-gap property is an essential tool for web developers working with grid layouts.

By specifying the space between columns, you can create a more organized and visually pleasing layout. Experiment with different gap values to see how they can enhance the design and usability of your grid-based web projects.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy