How to give space between label and textbox in bootstrap?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

In this tutorial, we will learn how to give space between label and textbox in bootstrap.

To give space between label and textbox, put .margin-left:5px class to create space in two label and textbox.

we can also apply left or right margin to put a space between label and input Inline.

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

Step 2: Includes bootstrap library

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

  <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: Define its class name

After that, create space between label and textbox with a class name margin-left:5px inline css.

  <form>
    <label for="fname">FirstName:</label> 
    <input style="margin-left:5px" type="text" id="quora" name="fname">
    <label for="fname">LastName:</label>
    <input style="margin-left:5px" type="text" id="fname" name="fname">
  </form>

Example.

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

<!DOCTYPE html>
<html lang="en">
<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>
</head>
<body>

<div class="container">
  <h2>Space between label and textbox in bootstrap</h2>
  <form>
    <label for="fname">FirstName:</label> 
    <input style="margin-left:5px" type="text" id="quora" name="fname">
    <label for="fname">LastName:</label>
    <input style="margin-left:5px" type="text" id="fname" name="fname">
  </form>
</div>
</body>
</html>

Check the output of the above code example.

Bootstrap, Label, Textbox

All the best 👍