how to give space between two div in bootstrap?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

In this tutorial, we will learn how to give space between two div in bootstrap.

To give space between two div, putting .col-* in the div tag gives space to the div.

Using div tag: Simply adding a div with padding in between two div tags gives spacing between the div.

Table of contents

  • Includes bootstrap view
  • Includes bootstrap library
  • Define its class name

Step 1: Includes bootstrap view

To ensure proper rendering and touch zooming for all devices, add the responsive viewport meta tag to your <head>.

    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

Step 2: Includes bootstrap library

First of all, load the Bootstrap framework CSS into the head tag of your webpage.

<!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
        integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" />
    <style media="screen">

Step 3: Define its class name

After that, create give space between two div with a class name between two div tags gives spacing between the div.

    <div class="container">
        <h2 class="text-center">Space between two div in bootstrap</h2>
        <div class="row">
            <div class="col-5 bg-warning a">
                Welcome To aGuideHub! ❤️
            </div>
            <div class="col-2">
                <!--extra div-->
            </div>
            <div class="col-5 bg-danger a">
                Welcome To aGuideHub! ❤️
            </div>
        </div>
    </div>

Example.

Let’s look at the following example to understand how it basically works:

<!DOCTYPE html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1,shrink-to-fit=no" />
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
        integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" />
    <style media="screen">
        .a {
            padding: 50px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2 class="text-center">Space between two div in bootstrap</h2>
        <div class="row">
            <div class="col-5 bg-warning a">
                Welcome To aGuideHub! ❤️
            </div>
            <div class="col-2">
                <!--extra div-->
            </div>
            <div class="col-5 bg-danger a">
                Welcome To aGuideHub! ❤️
            </div>
        </div>
    </div>
</body>
</html>

Check the output of the above code example.

Bootstrap, Space, Between, Two, Div

All the best 👍