How to give margin in bootstrap 3?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

In this tutorial, we will learn how to give margin in bootstrap 3.

To give margin, put .margin: 50px; class to create margin in bootstrap 3.

Table of contents

  • Includes bootstrap view
  • Includes bootstrap library
  • Includes css in html page
  • 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">

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://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

Step 3: Includes css in html page

Here we are using in css class to add margin in bootstrap 3.

  .top{
            margin: 50px;
            padding: 30px;
        }

Step 4: Define its class name

After that, create the margin with a class name .top.

     <div class="container">
        <h3> Margin in bootstrap 3 </h3>
        <div class="bg-danger top">
            aGuideHub
        </div>
    </div>

Example.

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

<!DOCTYPE html>
<html>

<head>
 <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
 <style>
        .top{
            margin: 50px;
            padding: 30px;
        }
    </style>
    <title>Margin in bootstrap 3</title>
</head>
<body>
    <div class="container">
        <h3> Margin in bootstrap 3 </h3>
        <div class="bg-danger top ">
            aGuideHub
        </div>
    </div>
</body>
</html> 

Check the output of the above code example.

Bootstrap, Margin

All the best 👍