Open In App

How to make Form Responsive using Bootstrap ?

We are going to create a responsive form by using Bootstrap 5. responsiveness is a feature that allows users to interact with the web app on any device easily. It helps to create better UI interactions and a better user experience that can be a reason to have great traffic on the respective website.

These are the following methods to make a form responsive:



Approach 1: Using Grid System

Example: This example shows the use of grid in Bootstrap for creation of responsive form.






<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,
                                   initial-scale=1.0">
    <title>Responsive Form with Bootstrap Grid System</title>
    <!-- Bootstrap CSS -->
    <link href=
          rel="stylesheet">
    <style>
        /* Additional styles */
        .form-control {
            margin-bottom: 10px;
        }
 
        .header {
            text-align: center;
            margin-bottom: 30px;
            color: green;
        }
    </style>
</head>
 
<body>
 
    <div class="container">
        <div class="header">
            <h3>GeeksForGeeks</h3>
        </div>
        <div class="row">
            <div class="col-md-6">
                <form>
                    <div class="mb-3">
                        <input type="text"
                               class="form-control"
                               placeholder="First Name">
                    </div>
                    <div class="mb-3">
                        <input type="text"
                               class="form-control"
                               placeholder="Last Name">
                    </div>
                    <div class="mb-3">
                        <input type="email"
                               class="form-control"
                               placeholder="Email">
                    </div>
                </form>
            </div>
            <div class="col-md-6">
                <form>
                    <div class="mb-3">
                        <input type="password"
                               class="form-control"
                               placeholder="Password">
                    </div>
                    <div class="mb-3">
                        <select class="form-control">
                            <option selected>Select Course</option>
                            <option>Course 1</option>
                            <option>Course 2</option>
                            <option>Course 3</option>
                        </select>
                    </div>
                    <button type="submit"
                            class="btn btn-primary">Submit</button>
                </form>
            </div>
        </div>
    </div>
 
</body>
 
</html>

Output:

form

Approach 2: Using Flexbox

Example: This example shows the use of Flexbox in Bootstrap for creation of responsive form.




<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,
                                   initial-scale=1.0">
    <title>Responsive Form with Bootstrap Grid System</title>
    <!-- Bootstrap CSS -->
    <link href=
          rel="stylesheet">
    <style>
        /* Additional styles */
        .form-control {
            margin-bottom: 10px;
        }
 
        .header {
            text-align: center;
            margin-bottom: 30px;
            color: green;
        }
    </style>
</head>
 
<body>
 
    <div class="container">
        <div class="header">
            <h3>GeeksForGeeks</h3>
        </div>
        <div class="row">
            <div class="col-md-6">
                <form class="d-flex flex-column">
                    <input type="text"
                           class="form-control mb-3"
                           placeholder="First Name">
                    <input type="text"
                           class="form-control mb-3"
                           placeholder="Last Name">
                    <input type="email"
                           class="form-control mb-3"
                           placeholder="Email">
                </form>
            </div>
            <div class="col-md-6">
                <form class="d-flex flex-column">
                    <input type="password"
                           class="form-control mb-3"
                           placeholder="Password">
                    <select class="form-control mb-3">
                        <option selected>Select Course</option>
                        <option>Course 1</option>
                        <option>Course 2</option>
                        <option>Course 3</option>
                    </select>
                    <button type="submit"
                            class="btn btn-primary">Submit</button>
                </form>
            </div>
        </div>
 
    </div>
 
</body>
 
</html>

Output:

form

Approach 3: Using Forms

Example: This example shows the use of Forms in Bootstrap for creation of responsive form.




<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,
                                   initial-scale=1.0">
    <title>Responsive Form with Bootstrap Grid System</title>
    <!-- Bootstrap CSS -->
    <link href=
          rel="stylesheet">
    <style>
        /* Additional styles */
        .form-control {
            margin-bottom: 10px;
        }
 
        .header {
            text-align: center;
            margin-bottom: 30px;
            color: green;
        }
    </style>
</head>
 
<body>
 
    <div class="container">
        <div class="header">
            <h3>GeeksForGeeks</h3>
        </div>
        <form>
            <div class="row">
                <div class="col-lg-6">
                    <div class="mb-3">
                        <input type="text"
                               class="form-control
                                      custom-margin"
                               placeholder="First Name">
                    </div>
                    <div class="mb-3">
                        <input type="text"
                               class="form-control
                                      custom-margin"
                               placeholder="Last Name">
                    </div>
                </div>
                <div class="col-lg-6">
                    <div class="mb-3">
                        <input type="email"
                               class="form-control
                                      custom-margin"
                               placeholder="Email">
                    </div>
                    <div class="mb-3">
                        <input type="password"
                               class="form-control
                                      custom-margin"
                               placeholder="Password">
                    </div>
                    <div class="mb-3">
                        <select class="form-control
                                       custom-margin">
                            <option selected>Select Course</option>
                            <option>Course 1</option>
                            <option>Course 2</option>
                            <option>Course 3</option>
                        </select>
                    </div>
                    <button type="submit"
                            class="btn btn-primary">
                          Submit</button>
                </div>
            </div>
        </form>
 
    </div>
 
</body>
 
</html>

Output:

form


Article Tags :