← Back to Bootstrap Course | Chapter 4: Colors & Spacing | Lesson 6 of 7

Gap utilities

Gap utilities space out the children of flex and grid containers without margins on each child.

In this page:

  1. Gap utilities
Syntax
markup
<div class="d-flex gap-3">
  <div>item</div>
  <div>item</div>
</div>

Gap utilities

On a .d-flex or .d-grid container, .gap-3 adds equal space between children. Use .row-gap-* and .column-gap-* for one direction. In the grid system the equivalent are gutter classes g-*, gx-* and gy-*.

Note: gap works on flex and grid containers only.

Example: Gap utilities

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
  <div class="d-flex gap-3 mb-3">
    <div class="bg-success text-white p-2">one</div><div class="bg-success text-white p-2">two</div><div class="bg-success text-white p-2">three</div>
  </div>
  <div class="d-flex flex-wrap column-gap-5 row-gap-1 border p-2">
    <span class="badge text-bg-secondary">a</span><span class="badge text-bg-secondary">b</span><span class="badge text-bg-secondary">c</span>
  </div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Using gap on non-flex elements
  2. Adding margins to every child instead
  3. Confusing gap with gutters
Chapter Summary
  • gap-* spaces flex and grid children
  • row-gap and column-gap control one axis
  • Grid gutters use g-*
  • No per-child margins needed
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.