Tillitsdone
down Scroll to discover

CSS Row-Gap Manage Space Between Rows

CSS row-gap property helps manage space between rows in flex and grid containers.

It accepts lengths, percentages, and global keywords for flexibility.
thumbnail

Understanding row-gap in CSS

The row-gap property in CSS helps you control the space between rows in flex and grid containers. It’s great for keeping your layouts clean and organized. Let’s dive into some examples.

Example: Using row-gap in Flexbox

HTML

<div class="flex-row-gap">
<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>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
</div>

CSS

.flex-row-gap {
background-color: #776fac;
padding: 5px;
display: flex;
flex-wrap: wrap;
row-gap: 25px;
}
.flex-row-gap > div {
background-color: aliceblue;
margin: 5px;
height: 80px;
line-height: 80px;
text-align: center;
font-size: 18px;
width: 100px;
}

Result

In this example, row-gap: 25px creates a 25-pixel gap between each row of items. This helps maintain consistent spacing and makes the layout look neat.

Example: Using row-gap in Grid Layout

HTML

<div class="grid-row-gap">
<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>

CSS

.grid-row-gap {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
row-gap: 25px;
height: 300px;
}
.grid-row-gap > div {
background-color: aliceblue;
border: 1px solid green;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
}

Result

In this grid example, row-gap: 25px creates a 25-pixel gap between each row. This keeps the grid items evenly spaced and visually appealing.

Interactive Example: Changing row-gap Values

HTML

<div class="flex-row-gap">
<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>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
</div>
<button onclick="changeRowGap('50px')">Set row-gap to 50px</button>
<button onclick="changeRowGap('normal')">Set row-gap to normal</button>
<button onclick="changeRowGap('initial')">Set row-gap to initial</button>
<button onclick="changeRowGap('inherit')">Set row-gap to inherit</button>

CSS

.flex-row-gap {
background-color: #776fac;
padding: 5px;
display: flex;
flex-wrap: wrap;
row-gap: normal;
}
.flex-row-gap > div {
background-color: aliceblue;
margin: 5px;
height: 80px;
line-height: 80px;
text-align: center;
font-size: 18px;
width: 100px;
}

JavaScript

function changeRowGap(value) {
document.querySelector('.flex-row-gap').style.rowGap = value;
}

Result

In this interactive example, you can change the row-gap value by clicking the buttons. This helps you see how different row-gap values affect the layout.

Browser Compatibility

The row-gap property is widely supported across modern browsers, making it a reliable choice for web developers. Here’s a quick overview:

BrowserInitial Support
Chrome50.0 (Apr 2016)
Firefox52.0 (Mar 2017)
IE/Edge10.0 (Sep 2012)
Opera37.0 (May 2016)
Safari9.0 (Sep 2015)

See Also

If you found the row-gap property useful, you might also be interested in exploring other related CSS properties and concepts:

  1. column-gap Property: Learn how to manage the space between columns.
  2. gap Property: Discover how to set both row and column gaps in one declaration.
  3. CSS Flexbox Tutorial: Dive into flexbox layouts.
  4. CSS Grid Layout Tutorial: Explore grid layouts.
  5. HTML Tutorial: Brush up on your HTML skills.

These resources will help you create more sophisticated and visually appealing web designs.

icons/css-4.svg CSS Blogs
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.