Home >>Bootstrap Tutorial >Bootstrap Input Groups

Bootstrap Input Groups

Bootstrap Input Groups

Input Groups in bootstrap are used to easily control default form by adding text, button groups, icons and button in front or behind the input field.

If you want to display the text in front of the input, add class .input-group-prepend and .input-group-append class is used to display text behind the input.

Let's take an example of bootstrap input groups:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap Input Groups</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container mt-3">
  <h3>Input Groups</h3>
  <form action="/action_page.php">
  <p>Prepend Group Example:</p>
    <div class="input-group mb-3">
      <div class="input-group-prepend">
        <span class="input-group-text">@</span>
      </div>
      <input type="text" class="form-control" placeholder="Username" id="usr" name="username">
    </div>
	  <p>Append Group Example:</p>
    <div class="input-group mb-3">
      <input type="text" class="form-control" placeholder="Your Email" id="mail" name="email">
      <div class="input-group-append">
        <span class="input-group-text">@example.com</span>
      </div>
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
  </form>
</div>
</body>
</html>
Output:

Input Groups

Prepend Group Example:

@

Append Group Example:

@example.com

Checkboxes and radios

You can also add radio or checkboxes instead of text in input field. By using bootstrap you can easily add checkboxes and radios by using the input type="checkbox" and input type="radio" in input field.

Let's take an example of checkboxes and radios:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap Input Groups</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container mt-3">
  <h3>Input Groups</h3>
  <form action="/action_page.php">
<div class="input-group mb-3">
  <div class="input-group-prepend">
    <div class="input-group-text">
      <input type="checkbox">
    </div>
  </div>
  <input type="text" class="form-control" placeholder="write text here....">
</div>
<div class="input-group mb-3">
  <div class="input-group-prepend">
    <div class="input-group-text">
      <input type="radio">
    </div>
  </div>
  <input type="text" class="form-control" placeholder="write text here....">
</div>
  </form>
</div>
</body>
</html>
Output:

Input Groups

Multiple inputs with Dropdown Buttons

You can easily display multiple inputs with dropdown button by adding a dropdown button in the input field.

Let's take an example of Multiple inputs with Dropdown Buttons:


<html>
<head>
  <title>Bootstrap Input Groups</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container mt-3">
  <h3>Multiple inputs with dropdown buttons</h3>
  <form action="/action_page.php">
  <p>Input group with dropdown button</p>
<div class="input-group mt-3 mb-3">
  <div class="input-group-prepend">
    <button type="button" class="btn btn-outline-secondary dropdown-toggle" data-toggle="dropdown">
      Dropdown button
    </button>
    <div class="dropdown-menu">
      <a class="dropdown-item" href="#">Link 1</a>
      <a class="dropdown-item" href="#">Link 2</a>
      <a class="dropdown-item" href="#">Link 3</a>
    </div>
  </div>
  <input type="text" class="form-control" placeholder="Username">
</div>
<p>Multiple Inputs</p>
<div class="input-group">
  <div class="input-group-prepend">
    <span class="input-group-text">First and last name</span>
  </div>
  <input type="text" aria-label="First name" class="form-control">
  <input type="text" aria-label="Last name" class="form-control">
</div>
  </form>
</div>
</body>
</html>
Output:

Multiple inputs with dropdown buttons

Input group with dropdown button

Multiple Inputs

First and last name

Sizing

Sometimes you want to change the size of input field. For this add class .input-group-sm (for small size), .input-group-lg (for large size) together with the class input-group.

Let's take an example of sizing inputs:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap Input Groups</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container mt-3">
  <h3>Input sizing</h3>
  <form>
  <div class="input-group mb-3 input-group-sm">
     <div class="input-group-prepend">
       <span class="input-group-text">input-group-sm</span>
    </div>
    <input type="text" class="form-control">
  </div>
</form>
<form>
  <div class="input-group mb-3">
    <div class="input-group-prepend">
      <span class="input-group-text">Default</span>
    </div>
    <input type="text" class="form-control">
  </div>
</form>
<form>
  <div class="input-group mb-3 input-group-lg">
    <div class="input-group-prepend">
      <span class="input-group-text">input-group-lg</span>
    </div>
    <input type="text" class="form-control">
  </div>
</form>
</div>
</body>
</html>
Output:

Input sizing

input-group-sm
Default
input-group-lg

Custom file input

You can also use custom file in input field for uploading any type of files. For adding custom file in input use input type="file".

Let's take an example of custom file input:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap Input Groups</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container mt-3">
  <h3>Custom file input</h3>
  <div class="input-group mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text" id="inputGroupFileAddon01">Upload</span>
  </div>
  <div class="custom-file">
    <input type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
    <label class="custom-file-label" for="inputGroupFile01">Choose file</label>
  </div>
</div>
<div class="input-group mb-3">
  <div class="input-group-prepend">
    <button class="btn btn-outline-success" type="button" id="inputGroupFileAddon02">Button</button>
  </div>
  <div class="custom-file">
    <input type="file" class="custom-file-input" id="inputGroupFile02" aria-describedby="inputGroupFileAddon02">
    <label class="custom-file-label" for="inputGroupFile02">Choose file</label>
  </div>
</div>
<div class="input-group">
  <div class="custom-file">
    <input type="file" class="custom-file-input" id="inputGroupFile03" aria-describedby="inputGroupFileAddon03">
    <label class="custom-file-label" for="inputGroupFile03">Choose file</label>
  </div>
  <div class="input-group-append">
    <button class="btn btn-outline-success" type="button" id="inputGroupFileAddon03">Button</button>
  </div>
</div>
<div class="input-group mb-3">
  <div class="custom-file">
    <input type="file" class="custom-file-input" id="inputGroupFile04">
    <label class="custom-file-label" for="inputGroupFile04" aria-describedby="inputGroupFileAddon04">Choose file</label>
  </div>
  <div class="input-group-append">
    <span class="input-group-text" id="inputGroupFileAddon04">Upload</span>
  </div>
</div>
</div>
</body>
</html>
Output:

Custom file input

Upload
Upload

Popular Tutorials