CSS Properties
CSS row-gap Property
Photo Credit to CodeToFun
🙋 Introduction
The row-gap
property in CSS is used to set the vertical spacing (gap) between rows in grid and flexbox layouts.
It is an essential property for controlling the layout and spacing of elements in a more manageable and visually appealing way.
💡 Syntax
The syntax for the row-gap
property is straightforward. It can be applied to grid and flexbox containers to specify the space between rows.
container {
row-gap: value;
}
Here, value can be any valid CSS length unit, such as px, em, rem, %, vh, vw, etc.
🎛️ Default Value
The default value of the row-gap
property is normal, which means the browser will use its default spacing. For grid layouts, this usually means no additional space between rows.
🏠 Property Values
Value | Description |
---|---|
length | Specifies a fixed gap between rows, such as 10px, 1em, etc. |
percentage | Specifies a gap relative to the size of the container, such as 10%. |
normal | The browser's default row gap, which is usually 0. |
📄 Example
In this example, we'll create a simple grid layout with a specified row gap.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS row-gap Example</title>
<style>
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr;
row-gap: 20px;
}
.grid-item {
background-color: #4caf50;
padding: 20px;
text-align: center;
color: white;
}
</style>
</head>
<body>
<h1>Grid Layout with Custom Row Gap</h1>
<div class="grid-container">
<div class="grid-item">Item 1</div>
<div class="grid-item">Item 2</div>
<div class="grid-item">Item 3</div>
<div class="grid-item">Item 4</div>
</div>
</body>
</html>
🖥️ Browser Compatibility
The row-gap
property is widely 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 row-gap
property is a powerful tool for web developers looking to control the vertical spacing between rows in grid and flexbox layouts.
By customizing the row gap, you can create more visually appealing and well-structured layouts. Experiment with different values to see how this property can enhance the look and feel of your web projects.
👨💻 Join our Community:
Author
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
If you have any doubts regarding this article (CSS row-gap Property), please comment here. I will help you immediately.