Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS row-gap Property

Posted in CSS Tutorial
Updated on Oct 07, 2024
By Mari Selvan
👁️ 12 - Views
⏳ 4 mins
💬 1 Comment
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.

Syntax
Copied
Copy To Clipboard
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

ValueDescription
lengthSpecifies a fixed gap between rows, such as 10px, 1em, etc.
percentageSpecifies a gap relative to the size of the container, such as 10%.
normalThe 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.

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

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