Related Articles

Related Articles

CSS | grid-gap Property
  • Last Updated : 08 Aug, 2019

The grid-gap property sets the size of the gap between the rows and columns in a grid layout.
It is a shorthand property for the following properties:

  1. grid-column-gap property
  2. grid-row-gap property

Syntax:

grid-gap: grid-row-gap grid-column-gap;

Property Values:

  • grid-row-gap: It sets the size of the gap between the rows in a grid layout. Its default value is 0.
  • grid-column-gap: It sets the size of the gap between the columns in a grid layout. Its default value is 0.

Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        CSS | grid-gap Property
    </title>
    <style>
        body {
            text-align: center;
        }
          
        h1 {
            color: black;
        }
        .grid-container {
            display: grid;
            grid-template-columns: auto auto auto;
            grid-column-gap: 50px;
            grid-row-gap: 10px;
            background-color: blue;
            padding: 10px;
        }
          
        .grid-container > div {
            background-color: white;
            text-align: center;
            padding: 20px 0;
            font-size: 30px;
        }
    </style>
</head>
  
<body>
  
    <h1>GeeksforGeeks</h1>
    <h2>Grid-column gap property</h2>
  
    <p>This grid has a 50px gap between
       columns and 10px gap between rows. :</p>
  
    <div class="grid-container">
        <div class="item1">G</div>
        <div class="item2">E</div>
        <div class="item3">E</div>
        <div class="item4">K</div>
        <div class="item5">S</div>
    </div>
  
</body>
  
</html>

chevron_right


Output:

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        CSS | grid-gap Property
    </title>
    <style>
        body {
            text-align: center;
        }
          
        h1 {
            color: green;
        }
          
        .grid-container {
            display: grid;
            grid-template-columns: auto auto auto;
            grid-column-gap: 8%;
            grid-row-gap: 5%;
            background-color: black;
            padding: 6%;
        }
          
        .grid-container > div {
            background-color: yellow;
            text-align: center;
            padding: 20px 0;
            font-size: 30px;
        }
    </style>
</head>
  
<body>
  
    <h1>GeeksforGeeks</h1>
    <h2>Grid-column gap property</h2>
  
    <p>This grid has a 8% gap between columns
       and 5% gap between rows:</p>
  
    <div class="grid-container">
        <div class="item1">G</div>
        <div class="item2">E</div>
        <div class="item3">E</div>
        <div class="item4">K</div>
        <div class="item5">S</div>
  
    </div>
  
</body>
  
</html>

chevron_right


Output:

Supported Browsers: The browsers supported by grid-gap property are listed below:

  • Google Chrome 57.0
  • Internet Explorer 16.0
  • Mozilla Firefox 52.0
  • Safari 10.0
  • Opera 44.0



My Personal Notes arrow_drop_up
Recommended Articles
Page :