Bootstrap 4 input group example

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To make an input group field, put the .input-group class in an input element it will show the input type group field on a page.

Today, I am going to show you. how to create input group in bootstrap 4 with code example.

Table of contents

  • Includes bootstrap view
  • Includes bootstrap library
  • Define its class name

This article will guide you to adding input group in Bootstrap 4 with example.

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 4 framework CSS into the head tag of your webpage.

<!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
    </script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js">
    </script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js">
    </script>

Step 3: Define its class name

After that, create the input group with a class name .input-group.

<div class="container">
        <h3> Input Group Example In Bootstrap - 4</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>
    </div>

Example.

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

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Input Groups in Bootstrap</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.3.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
    </script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js">
    </script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js">
    </script>
</head>

<body>
    <h1 style="color:red;text-align:center;">
        aGuideHub
    </h1>
    <div class="container">
        <h3> Input Group Example In Bootstrap - 4</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>
    </div>
</body>

</html>

Check the output of the above code example.

Bootstrap, Input, Group

All the best 👍

Premium Content

You can get all the below premium content directly in your mail when you subscribe us

Books

Interview Questions

Soon You will get CSS, JavaScript, React Js, and TypeScript So Subscribe to it.

Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

Related Posts