Open In App

Input Groups in Bootstrap with Examples

Last Updated : 03 Aug, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

Input Groups in Bootstrap are used to extend the default form controls by adding text or buttons on either side of textual inputs, custom file selectors, or custom inputs.

Basic input groups: The following classes are the base classes that are used to add the groups to either side of the input boxes. 

  • The .input-group-prepend class is used to add groups to the front of the input.
  • The .input-group-append class is used to add it behind the input.
  • The .input-group-text class is used to style the text that is displayed inside the group.

The following example demonstrates these input groups: 

html




<!DOCTYPE html>
 
<html>
 
<head>
    <!-- Include Bootstrap CSS -->
    <link rel="stylesheet"
          href=
    <title>Input Groups in Bootstrap</title>
</head>
 
<body>
    <div class="container">
        <h3>Prepend Group Example</h3>
 
        <!-- Declare an input group -->
        <div class="input-group">
 
            <!-- Prepend the following content to the input box -->
            <div class="input-group-prepend">
 
                <!-- Define the text content of the group -->
                <span class="input-group-text"
                      id="username">
                  @
                  </span>
            </div>
 
            <!-- Declare an input box -->
            <input type="text"
                   class="form-control"
                   placeholder="Username">
        </div>
 
        <h3>Append Group Example</h3>
 
        <!-- Declare an input group -->
        <div class="input-group">
 
            <!-- Declare an input group -->
            <input type="text"
                   class="form-control"
                   placeholder="Email">
 
            <!-- Prepend the following content to the input box -->
            <div class="input-group-append">
 
                <!-- Define the text content of the group -->
                <span class="input-group-text"
                      id="email">
                  @example.com
                  </span>
            </div>
        </div>
 
        <h3>Prepend and Append Together</h3>
 
        <!-- Declare an input group -->
        <div class="input-group">
 
            <!-- Prepend the following content to the input box -->
            <div class="input-group-prepend">
 
                <!-- Define the text content of the group -->
                <span class="input-group-text">
                  https://
                  </span>
            </div>
 
            <!-- Declare an input group -->
            <input type="text"
                   class="form-control"
                   placeholder="Your domain name here">
 
            <!-- Append the following content to the input box -->
            <div class="input-group-append">
 
                <!-- Define the text content of the group -->
                <span class="input-group-text">
                  .com
                  </span>
            </div>
        </div>
    </div>
</body>
 
</html>


Output: 

Prepend and Append

Sizing of the Input Groups

The input groups could be made larger or smaller by additional classes. There are 3 possible sizes of input groups:

  • The .input-group-sm class is used for a smaller size.
  • The .input-group-lg class is used for a larger size.
  • The .input-group class is the default size.

Note: Sizing on the individual input group elements isn’t currently supported.

Example: 

html




<!DOCTYPE html>
 
<html>
 
<head>
    <!-- Include Bootstrap CSS -->
    <link rel="stylesheet"
          href=
    <title>Input Groups in Bootstrap</title>
</head>
 
<body>
    <div class="container">
        <h1>Sizing</h1>
 
        <!-- Declare the small input group -->
        <div class="input-group input-group-sm mb-3">
 
            <!-- Prepend the following content to the input box -->
            <div class="input-group-prepend">
 
                <!-- Define the text content of the group -->
                <span class="input-group-text"
                      id="small">
                  Small
                  </span>
            </div>
 
            <!-- Declare an input box -->
            <input type="text"
                   class="form-control">
        </div>
 
        <!-- Declare the normal input group -->
        <div class="input-group mb-3">
 
            <!-- Prepend the following content to the input box -->
            <div class="input-group-prepend">
 
                <!-- Define the text content of the group -->
                <span class="input-group-text"
                      id="medium">
                  Default
                  </span>
            </div>
 
            <!-- Declare an input box -->
            <input type="text"
                   class="form-control">
        </div>
 
        <!-- Declare the large input group -->
        <div class="input-group input-group-lg">
 
            <!-- Prepend the following content to the input box -->
            <div class="input-group-prepend">
 
                <!-- Define the text content of the group -->
                <span class="input-group-text"
                      id="large">
                  Large
                  </span>
            </div>
 
            <!-- Declare an input box -->
            <input type="text"
                   class="form-control">
        </div>
    </div>
</body>
 
</html>


Output: 

Sizing of input groups

Using Multiple Inputs: Multiple inputs could be used with input groups.

Example: 

html




<!DOCTYPE html>
 
<html>
 
<head>
    <!-- Include Bootstrap CSS -->
    <link rel="stylesheet"
          href=
 
    <title>Input Groups in Bootstrap</title>
</head>
 
<body>
    <div class="container">
        <h3>Multiple inputs</h3>
 
        <!-- Declare an input group -->
        <div class="input-group">
 
            <!-- Prepend the following content to the input box -->
            <div class="input-group-prepend">
 
                <!-- Define the text content of the group -->
                <span class="input-group-text"
                      id="">
                  First & Last name
                  </span>
            </div>
 
            <!-- Declare two input boxes -->
            <input type="text" class="form-control">
            <input type="text" class="form-control">
        </div>
    </div>
</body>
 
</html>


Output: 

Multiple Inputs

Using Multiple Addons: Multiple addons could be stacked or mixed together with other types, including checkboxes and radio buttons.

Example: 

html




<!DOCTYPE html>
<html>
 
<head>
    <!-- Include Bootstrap CSS -->
    <link rel="stylesheet"
          href=
 
    <title>Input Groups in Bootstrap</title>
</head>
 
<body>
    <div class="container">
        <h1>Multiple addons</h1>
 
        <!-- Declare an input group -->
        <div class="input-group mb-3">
 
            <!-- Prepend the following content to the input box -->
            <div class="input-group-prepend">
 
                <!-- Declare two input groups -->
                <span class="input-group-text">
                  $
                  </span>
                <span class="input-group-text">
                  0.00
                  </span>
 
            </div>
            <!-- Declare an input box -->
            <input type="text"
                   class="form-control">
        </div>
 
        <!-- Declare an input group -->
        <div class="input-group">
 
            <!-- Declare an input box -->
            <input type="text"
                   class="form-control">
 
            <!-- Append the following content to the input box -->
            <div class="input-group-append">
 
                <!-- Declare two input texts -->
                <span class="input-group-text">
                  $
                  </span>
                <span class="input-group-text">
                  0.00
                  </span>
            </div>
        </div>
    </div>
</body>
 
</html>


Output: 

Multiple Addons

Using Button Addons: Buttons could also be appended or prepended to the input box.

Example: 

html




<!DOCTYPE html>
<html>
   
<head>
    <!-- Include Bootstrap CSS -->
    <link rel="stylesheet"
          href=
 
    <title>Input Groups in Bootstrap</title>
</head>
<body>
    <div class="container">
        <h1>Button addons</h1>
 
        <!-- Declare an input group -->
        <div class="input-group mb-3">
 
            <!-- Prepend the following content to the input box -->
            <div class="input-group-prepend">
 
                <!-- Declare a button-->
                <button class="btn btn-outline-secondary"
                        type="button">
                  Button
                  </button>
            </div>
 
            <!-- Declare an input box -->
            <input type="text"
                   class="form-control">
        </div>
 
        <!-- Declare an input group -->
        <div class="input-group mb-3">
 
            <!-- Declare an input box -->           
            <input type="text"
                   class="form-control">
 
            <!-- Append the following content to the input box -->
            <div class="input-group-append">
 
                <!-- Declare a button -->
                <button class="btn btn-outline-secondary"
                        type="button">
                  Button
                  </button>
            </div>
        </div>
 
        <!-- Declare an input group -->       
        <div class="input-group mb-3">
 
            <!-- Prepend the following content to the input box -->           
            <div class="input-group-prepend">
 
                <!-- Declare two buttons -->
                <button class="btn btn-outline-secondary"
                        type="button">
                  Button 1
                  </button>
                <button class="btn btn-outline-secondary"
                        type="button">
                  Button 2
                  </button>
            </div>
 
            <!-- Declare an input box -->
            <input type="text"
                   class="form-control">
        </div>
 
        <!-- Declare an input group -->            
        <div class="input-group mb-3">
 
            <!-- Declare an input box -->           
            <input type="text" class="form-control">
 
            <!-- Append the following content to the input box -->      
            <div class="input-group-append">
 
                <!-- Declare two buttons -->
                <button class="btn btn-outline-secondary"
                        type="button">
                  Button 1
                  </button>
                <button class="btn btn-outline-secondary"
                        type="button">
                  Button 2
                  </button>
            </div>
        </div>
    </div>
</body>
   
</html>


Output: 

Multiple Buttons

Using Custom Select: Input groups could be used with custom select.

Note: Browser default versions of custom select are not supported.

Example: 

html




<!DOCTYPE html>
<html>
 
<head>
    <!-- Include Bootstrap CSS -->
    <link rel="stylesheet"
          href=
    <title>Input Groups in Bootstrap</title>
</head>
 
<body>
    <div class="container">
        <h3>Custom select</h3>
 
        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <label class="input-group-text"
                       for="select01">
                  Options
                  </label>
            </div>
            <select class="custom-select"
                    id="select01">
                <option selected>Choose...</option>
                <option value="1">One</option>
                <option value="2">Two</option>
                <option value="3">Three</option>
            </select>
        </div>
 
        <div class="input-group mb-3">
            <select class="custom-select"
                    id="select02">
                <option selected>Choose...</option>
                <option value="1">One</option>
                <option value="2">Two</option>
                <option value="3">Three</option>
            </select>
            <div class="input-group-append">
                <label class="input-group-text"
                       for="select02">
                  Options
                  </label>
            </div>
        </div>
    </div>
 
    <script src=
      </script>
    <script src=
      </script>
    <script src=
      </script>
</body>
 
</html>


Output: 

Custom Select

Using Custom File Input: Input groups could be used with custom file inputs.

Note: Browser default versions of file inputs are not supported.

Example:  

html




<!DOCTYPE html>
<html>
 
<head>
    <!-- Include Bootstrap CSS -->
    <link rel="stylesheet"
          href=
    <title>Input Groups in Bootstrap</title>
</head>
 
<body>
    <div class="container">
        <h3>Custom file input</h3>
        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <span class="input-group-text">
                  Upload
                  </span>
            </div>
            <div class="custom-file">
                <input type="file"
                       class="custom-file-input"
                       id="file01">
                <label class="custom-file-label"
                       for="file01">
                  Choose file
                  </label>
            </div>
        </div>
 
        <div class="input-group mb-3">
            <div class="custom-file">
                <input type="file"
                       class="custom-file-input"
                       id="file02">
                <label class="custom-file-label"
                       for="file02">
                  Choose file
                  </label>
            </div>
            <div class="input-group-append">
                <span class="input-group-text"
                      id="">
                  Upload
                  </span>
            </div>
        </div>
    </div>
 
    <script src=
      </script>
    <script src=
      </script>
    <script src=
      </script>
</body>
 
</html>


Output: 

Custom File


Master JavaScript with our full Javascript - Beginner to Advanced online course! From basics to advanced techniques, build interactive websites and earn a certification. Take the Three 90 Challenge—complete 90% in 90 days for a 90% refund. Start now and unlock your JavaScript potential!


Next Article

Similar Reads

Bootstrap 4 | Input Groups
Input Groups in Bootstrap are used to extend the default form controls by adding text or buttons on either side of textual inputs, custom file selectors or custom inputs. Basic input groups: The following classes are the base classes that are used to add the groups to either side of the input boxes. The .input-group-prepend class is used to add gr
7 min read
Explain Input groups in Bootstrap Development
Input groups play an important role in collecting user information, their likes, and dislikes, feedback, and more. In this era of online business, it has become an integral part of any website to deal with customers. Normal forms are cool but adding customized input groups to it makes it cooler, interactive, and more user-friendly. In this articl
7 min read
Blaze UI Input Input-Groups
Blaze UI is a framework-free open-source UI toolkit. It provides a great foundation for building scalable websites faster. Blaze UI comes with a lot of pre-styled components and many utilities so that developers don’t have to build everything from scratch. In this article we will know about the Input Groups, there are lots of variety in inputs grou
3 min read
Bootstrap 5 Input group Custom file input
Bootstrap 5 Input Groups are used to extend form controls by adding the buttons, text, or button groups before or after the text inputs, custom selects, or file inputs.Bootstrap 5 Input group Custom file input ClassesThere is no specific class used to Input group Custom file input. To create a button, we use the .btn class and make a combination of
2 min read
Bootstrap 4 | Button Groups
Bootstrap offers classes which allow to group buttons along the same line, horizontally or vertically. The buttons to be grouped are nested inside a <div> element with the class .btn-group. Horizontally arranged button groups: The .btn-group class is used to create horizontally arranged button groups. Example: html <!DOCTYPE html> <h
4 min read
Bootstrap 4 | List Groups
List Groups are used to display a series of content in an organized way. Use .list-group and .list-group-item classes to create a list of items. The .list-group class is used with <ul> element and .list-group-item is used with <li> element. Example: HTML <!DOCTYPE html> <html lang="en"> <head> <title>
4 min read
How do we create large button groups in Bootstrap ?
Bootstrap is a free and open-source collection of CSS and JavaScript/jQuery code used for creating dynamic websites layout and web applications. It is one of the most popular front-end frameworks which has really a nice set of predefined CSS codes. It uses different types of classes to make responsive websites. Bootstrap 5 is the major release of B
5 min read
Bootstrap 5 Cards List groups
Bootstrap 5 Cards List groups are used to create a group of lists inside the card to show information like features, pricing, and many more. Cards List groups used Classes: No special classes are used in List groups. You can customize the component using List groups classes. Syntax: <div class="card" > <ul class="list-group list-group-flus
2 min read
Bootstrap 5 Checkbox and radio button groups
Bootstrap5 checkbox and radio button group provide to combine the button, such as checkbox and radio toggle buttons in a button group, by implementing the .btn-group class.Checkbox and Radio Button Group Classes:.btn-group: This class is used to combine buttons..btn-check: This class is used to create checkable type buttons.Syntax:<section class
2 min read
What are Button Groups in Bootstrap ?
"Button Groups" in Bootstrap is a class of name "btn-group" which is used to create a series of buttons in groups (without spaces) vertically or horizontally. Syntax: This is the basic syntax of the button group class where each button has its own class of "btn". <div class="btn-group"> <button type="button" class="btn">Click</button
3 min read
  翻译: