Categories
Web development

CSS gap Property

CSS gap Property

The CSS gap property specifies the size of the space between the rows and columns. It is a shorthand for the following properties:

Syntax:

gap: row-gap column-gap;

row-gap – sets the size of the space between the rows in a grid layout.

column-gap – sets the size of the space between the columns in a grid layout.

gap: 20px 20px;

is a shorthand for:

row-gap: 20px;
column-gap: 25px;

Example:

<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
  display: grid;
  grid-template-columns: auto auto auto;
  gap: 20px 25px;
}
.grid-container > div {
  border: 1px solid #333;
  background-color: #e9c46a;
}
</style>
</head>
<body>

<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>

</body>
</html>

Output:

1
2
3
4
5
6
7
8
9

Enjoy coding!

Read also:

CSS grid-auto-flow Property

CSS Grid Layout