Lesson 24 of 60 – Bootstrap Input Groups
40%

Bootstrap Input Groups

Bootstrap Input Groups allow you to combine form controls with text, icons, buttons, dropdowns, and other elements. They are useful for creating professional search boxes, currency fields, usernames, website URLs, phone numbers, and many other types of forms.

Note: An input group is created using the .input-group class. Additional text or elements are commonly placed inside .input-group-text.

1. What Is an Input Group?

An input group combines an input control with additional content on its left or right side.

<div class="input-group">

    <span class="input-group-text">
    @
    </span>

    <input type="text"
    class="form-control"
    placeholder="Username">

</div>
@

2. The .input-group Class

The .input-group class acts as the main wrapper for an input group.

<div class="input-group">

    <input
    type="text"
    class="form-control">

</div>

The wrapper allows related form elements to be displayed together.

3. The .input-group-text Class

The .input-group-text class is used for text or simple content placed next to an input.

<div class="input-group">

    <span class="input-group-text">
    $
    </span>

    <input
    type="text"
    class="form-control">

</div>
$

4. Text Before an Input

You can place text before an input using .input-group-text.

<div class="input-group">

    <span class="input-group-text">
    Name
    </span>

    <input
    type="text"
    class="form-control"
    placeholder="Enter name">

</div>
Name

5. Text After an Input

Text can also be placed after the input.

<div class="input-group">

    <input
    type="text"
    class="form-control"
    placeholder="Username">

    <span class="input-group-text">
    @example.com
    </span>

</div>
@example.com

6. Currency Input Group

Input groups are useful for displaying currency symbols with price fields.

<div class="input-group">

    <span class="input-group-text">
    ₹
    </span>

    <input
    type="number"
    class="form-control"
    placeholder="Amount">

</div>
₹

7. Percentage Input

You can use input groups to display a percentage symbol.

<div class="input-group">

    <input
    type="number"
    class="form-control"
    placeholder="Discount">

    <span class="input-group-text">
    %
    </span>

</div>
%

8. Username Input

An input group can make username fields easier to understand.

<div class="input-group">

    <span class="input-group-text">
    @
    </span>

    <input
    type="text"
    class="form-control"
    placeholder="Username">

</div>
@

9. Website URL Input

Input groups can be used to create website URL fields.

<div class="input-group">

    <span class="input-group-text">
    https://
    </span>

    <input
    type="text"
    class="form-control"
    placeholder="example.com">

</div>
https://

10. Email Input Group

An email symbol can be displayed before an email input.

<div class="input-group">

    <span class="input-group-text">
    @
    </span>

    <input
    type="email"
    class="form-control"
    placeholder="Email">

</div>
@

11. Input Group with Button

Buttons can be placed inside an input group.

<div class="input-group">

    <input
    type="text"
    class="form-control"
    placeholder="Search">

    <button
    class="btn btn-primary">

    Search

    </button>

</div>

12. Input Group with Search Button

Search fields are a common practical use of input groups.

<div class="input-group">

    <input
    type="search"
    class="form-control"
    placeholder="Search tutorials">

    <button
    class="btn btn-success">

    Search

    </button>

</div>

13. Input Group with Two Buttons

Multiple buttons can be placed next to an input.

<div class="input-group">

    <input
    type="text"
    class="form-control">

    <button
    class="btn btn-primary">
    Search
    </button>

    <button
    class="btn btn-secondary">
    Clear
    </button>

</div>

14. Input Group with Dropdown Button

An input group can contain a Bootstrap dropdown button.

<div class="input-group">

    <button
    class="btn btn-outline-secondary
    dropdown-toggle"
    data-bs-toggle="dropdown">

    Course

    </button>

    <ul class="dropdown-menu">

        <li>
        <a class="dropdown-item" href="#">
        HTML
        </a>
        </li>

        <li>
        <a class="dropdown-item" href="#">
        Python
        </a>
        </li>

    </ul>

    <input
    type="text"
    class="form-control">

</div>

15. Input Group with Checkbox

Checkboxes can also be placed inside input groups.

<div class="input-group">

    <div class="input-group-text">

        <input
        class="form-check-input mt-0"
        type="checkbox">

    </div>

    <input
    type="text"
    class="form-control"
    placeholder="Select option">

</div>

16. Input Group with Radio Button

Radio buttons can be placed inside an input group when appropriate.

<div class="input-group">

    <div class="input-group-text">

        <input
        class="form-check-input mt-0"
        type="radio"
        name="option">

    </div>

    <input
    type="text"
    class="form-control"
    value="HTML">

</div>

17. Input Group Sizing

Bootstrap provides large and small sizes for input groups.

<div class="input-group input-group-lg">

    <span class="input-group-text">
    ₹
    </span>

    <input
    class="form-control">

</div>

<div class="input-group">
    ...
</div>

<div class="input-group input-group-sm">
    ...
</div>
₹
₹
₹

18. Multiple Inputs in One Group

You can place multiple inputs inside one input group.

<div class="input-group">

    <span class="input-group-text">
    First and Last Name
    </span>

    <input
    type="text"
    class="form-control"
    placeholder="First name">

    <input
    type="text"
    class="form-control"
    placeholder="Last name">

</div>
First and Last Name

19. Input Group with Textarea

An input group can also be used with a textarea.

<div class="input-group">

    <span class="input-group-text">
    Message
    </span>

    <textarea
    class="form-control">
    </textarea>

</div>
Message

20. Input Group with Select

A select control can be combined with an input group.

<div class="input-group">

    <select
    class="form-select">

        <option>
        +91
        </option>

        <option>
        +1
        </option>

    </select>

    <input
    type="tel"
    class="form-control"
    placeholder="Phone number">

</div>

21. Input Group with Button on the Left

A button can be placed before the input.

<div class="input-group">

    <button
    class="btn btn-primary">
    Search
    </button>

    <input
    type="text"
    class="form-control"
    placeholder="Search here">

</div>

22. Input Group with Button on Both Sides

Buttons can be placed on both sides of an input.

<div class="input-group">

    <button
    class="btn btn-outline-secondary">
    -
    </button>

    <input
    type="number"
    class="form-control text-center"
    value="1">

    <button
    class="btn btn-outline-secondary">
    +
    </button>

</div>

23. Input Group with Validation

Input groups can contain form controls with validation classes.

<div class="input-group">

    <span class="input-group-text">
    @
    </span>

    <input
    type="email"
    class="form-control is-invalid"
    value="">

</div>

<div class="invalid-feedback">
Please enter a valid email.
</div>
@
Please enter a valid email address.

24. Input Group with URL

Input groups are useful for creating website and domain fields.

https:// .com
<div class="input-group">

    <span class="input-group-text">
    https://
    </span>

    <input
    type="text"
    class="form-control"
    placeholder="www.example">

    <span class="input-group-text">
    .com
    </span>

</div>

25. Input Group with File Button

A button can be used with a file input to create a file-selection interface.

<div class="input-group">

    <input
    type="file"
    class="form-control">

    <button
    class="btn btn-primary">
    Upload
    </button>

</div>

The actual upload still requires server-side processing.

26. Practical Search Input Group

A search bar is one of the most common uses of an input group.

<div class="input-group">

    <input
    type="search"
    class="form-control"
    placeholder="Search students">

    <button
    class="btn btn-primary">
    Search
    </button>

</div>

27. Practical Payment Input Group

A payment form can use an input group to display a currency symbol along with the amount.

₹ INR
<div class="input-group">

    <span class="input-group-text">
    ₹
    </span>

    <input
    type="number"
    class="form-control"
    placeholder="Enter payment amount">

    <span class="input-group-text">
    INR
    </span>

</div>

28. Input Group in a Responsive Layout

Input groups can be combined with Bootstrap's grid system to create responsive forms.

<div class="row">

    <div class="col-md-6 mb-3">

        <label class="form-label">
        Username
        </label>

        <div class="input-group">

            <span class="input-group-text">
            @
            </span>

            <input
            type="text"
            class="form-control">

        </div>

    </div>

    <div class="col-md-6 mb-3">

        <label class="form-label">
        Website
        </label>

        <div class="input-group">

            <span class="input-group-text">
            https://
            </span>

            <input
            type="text"
            class="form-control">

        </div>

    </div>

</div>
@
https://

29. Practical Student Admission Input Groups

Input groups can make student admission forms easier to understand and use.

+91
@
₹
https://

30. Complete Bootstrap Input Group Example

The following example combines labels, input groups, text prefixes, currency, buttons, and responsive grid classes.

<form>

    <div class="row">

        <div class="col-md-6 mb-3">

            <label class="form-label">
            Username
            </label>

            <div class="input-group">

                <span class="input-group-text">
                @
                </span>

                <input
                type="text"
                class="form-control"
                placeholder="Username">

            </div>

        </div>


        <div class="col-md-6 mb-3">

            <label class="form-label">
            Email
            </label>

            <div class="input-group">

                <span class="input-group-text">
                @
                </span>

                <input
                type="email"
                class="form-control"
                placeholder="Email">

            </div>

        </div>


        <div class="col-md-6 mb-3">

            <label class="form-label">
            Course Fee
            </label>

            <div class="input-group">

                <span class="input-group-text">
                ₹
                </span>

                <input
                type="number"
                class="form-control"
                placeholder="Amount">

                <span class="input-group-text">
                INR
                </span>

            </div>

        </div>


        <div class="col-md-6 mb-3">

            <label class="form-label">
            Search
            </label>

            <div class="input-group">

                <input
                type="search"
                class="form-control"
                placeholder="Search">

                <button
                type="button"
                class="btn btn-primary">

                Search

                </button>

            </div>

        </div>


        <div class="col-12">

            <button
            type="submit"
            class="btn btn-success">

            Submit

            </button>

        </div>

    </div>

</form>
@
@
₹ INR

📌 Key Points

  • Use .input-group as the main input group wrapper.
  • Use .input-group-text for text or simple content beside an input.
  • Input groups can contain prefixes and suffixes.
  • You can combine input groups with buttons.
  • Dropdown buttons can be used inside input groups.
  • Checkboxes and radio buttons can be placed inside input groups.
  • Use .input-group-lg for larger input groups.
  • Use .input-group-sm for smaller input groups.
  • Input groups can contain multiple inputs.
  • Input groups can be combined with select controls and textareas.
  • Input groups are useful for currency, percentage, username, URL, phone, and search fields.
  • Bootstrap grid classes can make input groups responsive.
  • Server-side validation is still required when processing submitted data.
  • Use meaningful labels with form controls.
  • Keep input groups simple so users can easily understand what each field expects.

🧠 Quick Quiz

Question: Which Bootstrap class is used as the main wrapper for an input group?